If a call to a service function results in an error, Flash Remoting returns a FaultEvent object as an argument to the fault handling method that you specify in the responder object. The responder can be a custom ActionScript object that you create, which implements the mx.rpc.Responder interface, or the provided interface, mx.rpc.RelayResponder. Flash Remoting returns an error if either of the following conditions occur:
fault property of the FaultEvent object.
You can import the FaultEvent class using the following import statement:
import mx.rpc.FaultEvent;
For more information about how to use a FaultEvent object in an application, see Handling service results and errors. For information about the RelayResponder class, see RelayResponder class.
Example
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_Fault() function is the fault-handling function for this service call. The fault-handling function receives a FaultEvent object (fault) as an argument. This object describes the fault that occurred on the service function call. Handling the fault in this case consists of assigning the faultstring property (fault.fault.faultstring) 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 version of the helloWorld_Fault fault-handling function uses the NetDebug.trace() method to give a more thorough account of the error that occurred by displaying all the properties of the fault object in the NetConnection Debugger.
function hello_World_Fault( fault:FaultEvent ):Void {
// notify the user of the problem
//
trace("There was a problem: " + fault.fault.faultstring);
trace("The faultcode is: " + fault.fault.faultcode);
trace("The detail: " + fault.fault.detail);
trace("The error class name is: " + fault.fault.type);
}
For more information about the NetConnection Debugger, see The NetConnection Debugger.
See Also
mx.remoting.debug.NetDebug
mx.remoting.PendingCall
mx.remoting.Service
mx.rpc.RelayResponder
mx.rpc.ResultEvent
| Properties | |
| fault:
Fault [
Read-Only]
Provides access to the fault that occurred. |
| Property Detail |
fault:
Fault [
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/FaultEvent.html