Handling service results and errors
45
mx.remoting.debug.NetDebug.trace({level:"None",
message:"There was a problem: " + fault.fault.faultstring });
}
When you specify a RelayResponder object for a service, results for all service functions are
relayed to the specified result and fault handling methods, which you must provide.
Using PendingCall and RelayResponder objects for a specific service function
After the Flash client application calls a service function, it does not stop executing to wait for the
return value; it continues to execute and specify which methods will handle the result or the fault
condition that the service function returns.
A call to a service method immediately returns a PendingCall object, which has a
responder
property. You can handle the result and fault outcomes for each service method by creating an mx.
rpc.RelayResponder object, or any ActionScript object that implements the mx.rpc.Responder
interface, and assign it to the
responder
property of the PendingCall object.
For example, in the following code, the
petMarketConn()
function calls the
getCategories()
method of the petMarketService object. The return value is a PendingCall object,
temp_pc
. The
code assigns a RelayResponder object to the
responder
property of
temp_pc
. The constructor for
the RelayResponder object specifies that
getCategories_Result()
function is the function to
handle a result outcome and
getCategories_Fault()
function is the function to handle a fault
outcome.
function petMarketConn() {
petMarketService = new Service(
"http://examples.macromedia.com/flashservices/gateway",
new Log(),
"petmarket.api.catalogservice",
null,
null);
var temp_pc:PendingCall = petMarketService.getCategories("en_US");
temp_pc:responder = new
RelayResponder(this,"getCategories_Result","getCategories_Fault");
}
function getCategories_Result(result:ResultEvent){
// display successful result
myGrid.dataProvider = result.result;
}
function getCategories_Fault(var fault:FaultEvent):Void {
message_txt.text = fault.fault.description;
}
For more information on the PendingCall and RelayResponder objects, see the PendingCall class
and the RelayResponder class in Flash Remoting ActionScript Dictionary Help.
Using the ResultEvent class
A successful call to a service function returns a ResultEvent object as an argument to the result
handling method. The ResultEvent object contains a
result
property, which stores the result
object that the service function returned.