![MACROMEDIA FLASH REMOTING MX Use Manual Download Page 46](http://html1.mh-extra.com/html/macromedia/flash-remoting-mx/flash-remoting-mx_use-manual_687566046.webp)
46
Chapter 2: Using Flash Remoting ActionScript
Handling the result object requires knowledge of the service function. The service function could
return a simple string, as shown in the following
HelloWorld_Result()
method:
function
serviceFunctionName
_Result(result:ResultEvent)
{
// display successful result
messageDisplay.text = result.result;
}
The service function could also return a complex object such as a record set holding several
records that were retrieved from a database. The
onCategoryData()
method, which is the result
handling method for the call to the
custService.getCategories()
method, receives a record
set and binds the Name and ID fields of the records in the record set to the
custCat_cmbo
ComboBox. In this case, the
result
property (
re.result
) holds the record set that is passed to
the
DataGlue.bindFormatStrings()
function.
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 more information about the ResultEvent class, see the ResultEvent class in Flash Remoting
ActionScript Dictionary Help.
Using the FaultEvent class
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 specified in the RelayResponder object. The
FaultEvent object contains a
fault
object (
mx.rpc.Fault
), which has
faultcode
,
faultstring
,
description
,
detail
, and
type
properties. These properties contain information
about the error that occurred including a code, descriptions, a stack trace, and the error class
name. You can display this information to the application user in order to document the error. In
the following example, the
onCategoryFault()
fault handling function receives a FaultEvent
object and calls the
NetDebug.trace()
method to display a description of the error (
fault.
fault.faultstring
).
function onCategoryFault( fault:FaultEvent ):Void {
// notify the user of the problem
mx.remoting.debug.NetDebug.trace({level:"None",
message:"There was a problem: " + fault.fault.faultstring });
}
For more information about the FaultEvent object, see the FaultEvent class in Flash Remoting
ActionScript Dictionary Help.