20.7. Handling Flash Remoting Results
Problem
You want to handle the results from calling a service function using Flash Remoting.
Solution
Use a named result function or, as a better alternative, use a response object.
Discussion
Unlike invocations of functions and methods that are defined within
the Flash movie, Flash Remoting service function invocations are
asynchronous. This means that when the ActionScript interpreter
encounters a remote service function call within the code, it
initiates the call but does not wait for a response before continuing
to the next line of ActionScript code. The same thing is true when
loading any external content, be it by means of an
XML
object, a LoadVars
object, or a movie clip using loadMovie( )
. This
asynchronous behavior allows the Flash movie to continue to run
without waiting on something that has the potential for high latency.
Therefore, if a remote service function returns a value, you cannot
use that value within your ActionScript code immediately, as you
would the return value of a native ActionScript function or method.
// myVariable
is undefined because the service function
// does not return a value immediately.
myVariable = myService.myServiceFunction(responseObject);
Instead, you have to use a response object with callback functions or methods to obtain the result. There are two ways to handle results from a Flash Remoting service function, and they correspond to the two variations of invoking the service function (see Recipe 20.6 ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.