Flash Remoting application structure
31
5.
Configure Flash Remoting (create a gateway and a reference to a remote service).
6.
Call service functions and pass parameters.
7.
Handle the results and error status information returned to Flash in result event-handler
routines.
The following ActionScript example connects to the
petmarket.api.catalogservice
service,
creates the
catalogService
Service object, and calls two service functions,
catalogService.
getCategories()
and
catalogService.getProducts()
. These functions have corresponding
result-handler callback methods,
gotCategories_Result()
and
gotProducts_Result()
to
show the results in the Flash application. They also has corresponding fault-handler callback
methods,
gotCategories_Fault()
and
got_Categories_Result()
, to handle any error
information if the service call fails.
Import Flash
Remoting
ActionScript
classes
Configure Flash
Remoting
Call the service
function(s)
callback functions
handle returned
result and fault
information
import mx.remoting.Service;
import mx.services.Log;
import mx.rpc.RelayResponder;
import mx.remoting.PendingCall;
import mx.remoting.RecordSet;
import mx.rpc.ResultEvent;
import mx.rpc.FaultEvent;
// Remove the slashes in the following two lines to use the
NetConnection Debugger
// import mx.remoting.debug.NetDebug;
// NetDebug.initialize();
function makePetMarketCalls(){
var catalogService:Service = new Service(
"http://examples.macromedia.com/flashservices/gateway",
new Log(),
"petmarket.api.catalogservice",
null,null );
var cat_pc:PendingCall =
catalogService.getCategories({locale:"en_US"});
cat_pc.responder = new RelayResponder(this,"gotCategories_Result",
"gotCategories_Fault");
var prod_pc:PendingCall = catalogService.
getProducts({categoryoid:5});
prod_pc.responder = new RelayResponder(this,"gotProducts_Result",
"gotProducts_Fault");
}
function gotCategories_Result(re:ResultEvent):Void{
trace("Got " + re.result. " Categor" + (re.result.
length>1?"ies":"y"));
}
function gotCategories_Fault(fault:FaultEvent):Void{
trace("Categories Fault: " + fault.fault.description);
}
function gotProducts_Result(re:ResultEvent):Void{
trace("Got " + re.result. " Product" + (re.result.
length>1?"s":""));
}
function gotProducts_Fault(fault:FaultEvent):Void{
trace("Products Fault: " + fault.fault.description);
}
makePetMarketCalls();