O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required