Handling results for a Connection object
167
Handling results for a Connection object
When you use the methods of the NetServices object to create a gateway connection and obtain a
Connection object, you use the
Connection.getService()
method to access a service. When
you access a service using the methods of the Connection object, you can either direct all results
for a service to a single object or direct the results of a specific service call to a specific result
handler.
Note:
Do not specify a responder object in the
gatewayConnection.getService()
method and in the
service function call. If you specify the responder in both places, Flash Remoting passes the
responder you specify as an argument to the service function. This behavior causes errors in your
application.
When you test an application in Flash during development, if there is no appropriate responder
object method, Flash displays the results in a message window.
Directing all results for a service to a single responder object
You can direct all results for a service to a single result handler by specifying a responder object as
the second argument of the
getService()
method call. The following example uses the
Connection.getService()
method to access the
remoteservices
service and specifies
HelloResponder
as the responder object to receive the results.
howdyService=gatewayConnection.getService("remoteservices",
new HelloResponder()); // responder
You can direct results to a specific method in the result handler by providing a method with the
name
serviceFunctionName_
Result()
, where
serviceFunctionName
is the name of the
service method.
Any results that are not directed to a specific result handler method are directed to the
onResult()
method.
Use this technique if all the following conditions are true:
•
The results of calls to one function name must be handled differently from the results of calls
to another function.
•
All functions in all services that require different handling have unique names. For example,
you do not use two services with identically named functions, such as
myFirstService.myFunction
and
myOtherService.myFunction
, that require different
processing.
•
The results of all calls to a particular function in a service can be handled by a single responder.
The following example shows how you can use the main SWF file as the responder and have a
common
onResult()
method result handler for some service functions, and function-specific
functionName_Result
handlers for other functions. In this example, there are two function-
specific result handlers, the
helloWorld_Result()
and the
whatsUp_Result()
method, which
display the returned message in specific text boxes. The default
onResult()
response handler
displays the result in the Output panel.
import mx.remoting.NetServices;
import mx.remoting.Connection;
Содержание FLASH REMOTING MX
Страница 1: ...Using Flash Remoting for Flash MX 2004 ActionScript 2 0...
Страница 8: ...8 Contents...
Страница 62: ...62 Chapter 3 Using the RemotingConnector component Flash Professional only...
Страница 142: ...142 Chapter 7 Using Flash Remoting for Java...