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.6. Invoking a Remote Function on a Service

Problem

You want to call a service function from a Flash movie (see Table 20-1 for Flash Remoting service function types).

Solution

Create a service object by invoking the getService( ) method from the connection object returned by createGatewayConnection( ). The service object is the object returned by getService( ). Then call the service function (any function defined for the service) as a method of the service object.

Discussion

The first step in calling a service function from a Flash movie is to create a connection object (see the Introduction and Recipe 20.1 for more information about this). For example:

#include "NetServices.as"
NetServices.setDefaultGatewayURL("http://localhost/flashservices/gateway");
myConnection = NetServices.createGatewayConnection(  );

Once you have created the connection object, you can create an object that maps to any service available through the specified gateway using the getService( ) method. There are two variations when using the getService( ) method. In the first variation, you specify a single response object to handle responses from all functions invoked on the object. In the second variation, instead of specifying the response object when invoking getService( ), you specify it as the first parameter each time you invoke a service function.

Both variations require that you provide the name of the service as it is known to the Flash Remoting gateway. A service is known by the URL that accesses the ...

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