Service.xml:
<?xml version="1.0" encoding="utf-8"?>
<business:ServiceLocator xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:business="com.adobe.cairngorm.business.*">
<!--commented for demo-->
<!--
<mx:RemoteObject
id="addcontactService"
destination="addcontactService"
showBusyCursor="true"
result="event.token.resultHandler( event );"
fault="event.token.faultHandler( event );">
</mx:RemoteObject>
-->
<mx:RemoteObject id="myService" destination="funds"
result="event.token.myResultHandler(event);"
fault="event.token.myFaultHandler(event);">
</mx:RemoteObject>
</business:ServiceLocator>
MyDelete.as
public function MyDelegate( responder : IResponder )
{
trace("88888888888888888888");
this.service = ServiceLocator.getInstance().getRemoteObject( "myService" );
trace("***********************************");
this.responder = responder;
}
public function getData(): void
{
var token : AsyncToken = service.getFunds();
trace("$$$$$$$$$$$$$$$$$$$$$$$$$$$");
token.myResultHandler = responder.result;
trace("******************#################");
token.myFaultHandler = responder.fault;
trace("++++++++++++++++++++++++++++++++++++++");
//for demo purpose: simulate remote service result
// setTimeout( addcontactResult, 1000, contactVO );
}
GetDataCommand.as
public function execute( event : CairngormEvent ) : void
{
var delegate : MyDelegate = new MyDelegate( this );
// var addcontactEvent : AddContactEvent = AddContactEvent( event );
trace("d222222222222222222222");
delegate.getData();
public function result( data:Object) : void
{
trace("d111111111111111111111");
trace(ObjectUtil.toString(data.result));
model.contracts = ArrayCollection (data.result);
}
public function fault( info:Object ) : void
{
trace("############################");
Alert.show("error occur");
}
打印结果是:
new model
333333333
88888888888888888888
***********************************
d222222222222222222222
$$$$$$$$$$$$$$$$$$$$$$$$$$$
******************#################
++++++++++++++++++++++++++++++++++++++
d111111111111111111111
(mx.collections::ArrayCollection)#0
说明fault 并没有执行,其执行顺序可能为:
1。 this.service = ServiceLocator.getInstance().getRemoteObject( "myService" );
2。 trace("$$$$$$$$$$$$$$$$$$$$$$$$$$$");
token.myResultHandler = responder.result;
trace("******************#################");
token.myFaultHandler = responder.fault;(此时只是赋值操作,responder.result与responder.fault 并没有执行)
3。 返回成功执行“token.myResultHandler()"