![MACROMEDIA FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT... Use Manual Download Page 44](http://html1.mh-extra.com/html/macromedia/flash-remoting-mx-using-flash-remoting-for-flash-mx-2004-actionscript/flash-remoting-mx-using-flash-remoting-for-flash-mx-2004-actionscript_use-manual_3385355044.webp)
44
Chapter 2: Using Flash Remoting ActionScript
If you create a RelayResponder object at the time that you create a Service object, the result and
fault handling methods must handle the result and fault outcomes for all functions that you call
on that service.
Flash Remoting returns a fault event instead of a result if either of the following conditions occur:
•
The Flash Remoting gateway encounters an error.
•
A service function encounters an error (throws an exception).
You write fault handlers to respond to the errors, typically by displaying an error message or
logging the error information. In some cases, you might be able to include recovery code, such as
code to retry a call to a busy server, in the error handler.
For information on handling result and fault outcomes when you have connected to a service
using the deprecated NetServices class, see
Appendix A, “Using NetServices and Connection
Classes,” on page 163
.
Using the RelayResponder object for a service
To direct all results for a service to a single object, specify a RelayResponder object for the
responder
parameter when you create the Service object. For example, the
responder
parameter, which is the last parameter, of the following Service constructor specifies that the
onCustData()
method is the result handler and the
onCustFault()
method is the fault handler
method. It also specifies with the first parameter that this object (
this
) contains both methods.
// Service constructor creates RelayResponder
custService = new Service(
"http://localhost:8300/flashservices/gateway",
null,
"CustomerInfo",
null,
new RelayResponder(this, "onCustData", "onCustFault"));
// …
// Result handling method specified in RelayResponder for custService
function onCustData( re:ResultEvent ):Void {
// update customer grid
var rs:RecordSet = RecordSet( re.result );
rs.setDeliveryMode( "onDemand" );
// create columns
if( customers_grd.columnCount == 0 ) {
var col:DataGridColumn = new DataGridColumn( "ID" );
customers_grd.addColumn( col );
col = new DataGridColumn( "Active" );
col.width = 80;
customers_grd.addColumn( col );
col = new DataGridColumn( "Name" );
col.width = 100;
customers_grd.addColumn( col );
customers_grd.addEventListener( "change", onCustGrid_Change );
}
// Fault handling method specified in RelayResponder
function onCustFault( fault:FaultEvent ):Void {
// notify the user of the problem
//…