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