- Home
- Tutorials
- Flash
- Intermediate
- Flash Remoting & FlashCom Server

Methods
Copyright © 2004 O'Reilly Media, Inc. All Rights Reserved. | ![]() |
| This content is excerpted from the above-named O'Reilly publication, with permission, by agreement with ActionScript.org. | |
Once you've established a connection and created a service object, you can make calls on that object to access methods of the service. The getService( ) method returns a proxy object to the service. The proxy object uses the NetConnection.call( ) syntax internally but provides a familiar way to invoke a remote method. The syntax to call a remote method is similar to any other method invocation:
serviceProxy.methodname([responseObject] [, arg1, ...argn])
The first parameter, responseObject, is an
optional response object, which overrides the default response object
passed to the getService( ) method. This
approach allows you to use different responders for each method call
instead of using the same handler for all methods invoked on the
service. In most situations, this is the preferred approach. It lets
you handle the results differently for each type of method invoked,
or even for each invocation of a given method.
If the first argument is an object defining an onResult( ) method, Flash strips it from the argument list passed to the remote service and uses it as a response object instead (the response object parameter is not passed to the remote method).
Warning
However, if you set a response object via getService( ) and attempt to specify another response object when invoking a remote function, it won't work. The response object will be passed as a parameter to the remote function instead of being stripped out of the argument list. See "Creating Responder Functions" in Chapter 4 of Flash Remoting: The Definitive Guide for many more details.
The remaining parameters in the remote method invocation are the arguments that the remote method expects. You can pass the arguments in two ways. The first approach is to pass the parameters as individual arguments separated by commas. Here is an example in which the optional response object is included as the first parameter:
serviceProxy.someMethod(someResponseObj, "one", "two", "three");
Here is the same method invocation without the optional response object:
serviceProxy.someMethod("one", "two", "three");
Passing unnamed parameters is similar to how parameters are passed when invoking any ActionScript method, and the names of the parameters do not need to be known to the client. However, the order that the remote server expects the arguments must be known to and observed by the client code. Normally with remote methods that require a single or only a few parameters, this is not an issue. But with remote methods that require many parameters, such as the Google search service, this can be a major source of problems.
The second approach is to wrap all of the parameters into a single object as name/value pairs and pass the object as the only parameter (besides the optional response object, not used in this example):
params = {one:"one", two:"two", three:"three"};
serviceProxy.someMethod(params);
The major advantage to this approach is that the order and number of the arguments becomes irrelevant because they are named values. The disadvantage is that the client must know the names that the server expects for each parameter.

