NetConnection.call( )

NetConnection.call( ) MethodFlash 6

invokes a server-side method from client-side ActionScript
myNetConnectionObject.call(remoteMethod, resultObject, arg1,...argn)

Arguments

remoteMethod

The name of the server-side method to invoke, in the format serviceName.methodName. The syntax for calling the method varies with the server technology, as described in earlier chapters.

resultObject

An ActionScript object with an onResult( ) method to handle results from the call to the server-side method. You can also pass null, in which case no results are handled.

arg1, ...argn

Zero or more arguments to be passed to the remote method. The third argument passed to the call( ) method (i.e., arg1) is passed as the first argument to the remote method. The next argument, arg2, is passed as the second argument to the remote method, and so on.

Returns

Return value of the remote method is passed to the onResult( ) handler of resultObject.

Description

The call( ) method is used to invoke a remote method through the NetConnection object. The call( ) method is not typically used directly by a developer. Instead, the developer typically uses the getService( ) method, which is a wrapper around the call( ) method that also adds more functionality. Using call( ), you have to create responder objects that contain onResult( ) and onStatus( ) methods; you can't use the named function methodname_onResult( ) or methodname_onStatus( ) techniques shown elsewhere in this book.

Because the call( ) method is a core method of the NetConnection object, you don't have to include the NetServices.as file in your Flash application to use it.

Example

The following code shows the basic syntax of the call( ) method:

// Create a responder object
var myResult = new Object( );
// Create an onResult( ) method to handle results from the call to the remote method
myResult.onResult = function (result) {
  display_txt.text = result;
};

// Create the connection
var my_conn = new NetConnection( );
// Attach a URL for the gateway
my_conn.connect("http://127.0.0.1/flashservices/gateway");
// Call the remote method
my_conn.call("com.oreilly.frdg.HelloUser.sayHello", myResult, firstname_txt.text);
// Nullify the connection
my_conn.close( );

In this case, a remote method named sayHello( ) in the com.oreilly.frdg.HelloUser service is invoked with one argument: firstname_txt.text. A responder object is created before calling the remote method and is passed as the second argument to call( ). The onResult( ) method of the responder object receives the response from the remote method call.

See Also

NetConnection.getService( ); Chapter 4



    Part III: Advanced Flash Remoting