A successful call to a service function returns a ResultEvent object as an argument to the result handling method that you specify in the responder object. The ResultEvent object contains a result property that stores the data that the service function returns. For example, if the service function accesses a database, the result property could be set to a RecordSet object that contains the records retrieved from the database. The characteristics of the returned ResultEvent object require knowledge of the service function that was called and the data that it returns.
The responder object can be any ActionScript object that implements the mx.rpc.Responder interface. The Responder interface exposes two methods (onResult() and onFault()) that respond to the result and faults for the current pending call. For convenience the Flash Remoting API provides the mx.rpc.RelayResponder interface.
You can import the ResultEvent class using the following import statement.
For more information about how to use a ResultEvent object in an application, see Handling service results and errors. For information about the RelayResponder class, see RelayResponder class.
import mx.rpc.ResultEvent;
helloWorld() service function. First, the application creates the howdyService Service object to connect to the remoteservices service and then calls the helloWorld() service function. Next, it creates a RelayResponder object that specifies that the helloWorld_Result() function is the result handling function for this service call. The result handling function receives a ResultEvent object (resultEvent) as an argument that contains the result of the service function call. Handling the result simply consists of assigning the content of the result property (resultEvent.result) to the messageDisplay text field, which is displayed by the Flash interface.
import mx.remoting.Service;
import mx.services.Log;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.PendingCall;
import mx.remoting.RecordSet;
// connect to service and create service object
howdyService = new Service(
"http://localhost:8300/flashservices/gateway",
new Log(),
"remoteservices",
null,
null );
// call the service helloWorld() function
var pc:PendingCall = howdyService.helloWorld();
// tell the service what methods handle the result and the fault condition
pc.responder = new RelayResponder( this, "helloWorld_Result", "helloWorld_Fault" );
function helloWorld_Result(resultEvent:ResultEvent)
{
// display successful result
messageDisplay.text = resultEvent.result;
}
function helloWorld_Fault(fault:FaultEvent)
{
// display fault returned from service
messageDisplay.text = fault.fault.faultstring;
}
For the complete Hello World application, see Building a Hello World application with Flash Remoting.
The following result handling function, onCategoryData(), which is taken from the CustomerInfoExampleAPI sample application, receives the ResultEvent object, re. In this case, re contains a RecordSet object of categories that have been returned by the getCategories() service function. After displaying a debug message that indicates it was called, onCategoryData() calls the DataGlue.bindFormatStrings() function to bind the Name and ID fields from the record set, accessed in the re.result property, to the custCat_cmbo ComboBox in the Flash interface. The function then assigns an event listener to the ComboBox to detect any change to the content of the ComboBox. Finally the function calls the refreshCustomerData() function to display the customers for the selected category.
function onCategoryData( re:ResultEvent ):Void {
mx.remoting.debug.NetDebug.trace({level:"Debug",
message:"onCategoryData" });
// use data glue to remap the fields so that label = name field and
// data = id field
DataGlue.bindFormatStrings( custCat_cmbo, re.result, "#Name#", "#ID#" );
custCat_cmbo.addEventListener( "change", onCustCat_Change );
refreshCustomerData();
}
For information about the complete CustomerInfoExampleAPI sample application, see Using the Flash Remoting ActionScript API in the CustomerInfoExampleAPI application.
See Also
mx.rpc.FaultEvent
mx.rpc.RelayResponder
mx.remoting.DataGlue
mx.remoting.PendingCall
mx.remoting.RecordSet
| Properties | |
| result:
Object [
Read-Only]
Provides access to the result |
| Property Detail |
result:
Object [
Read-Only]
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flashremoting/mx2004/actionscript_api_reference/mx/rpc/ResultEvent.html