Handler result event and fault event for ItemResponder
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
import mx.collections.ItemResponder;
import mx.controls.Alert;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
[Bindable]
private var myData:ArrayCollection
private var contactService:HTTPService = new HTTPService();
private function getData():void{
contactService.url="contacts.xml";
var responder:ItemResponder = new ItemResponder(resultHandler,faultHandler);
var token:AsyncToken = contactService.send();
token.addResponder(responder);
}
private function resultHandler(event:ResultEvent, token:AsyncToken):void{
myData = event.result.contacts.row;
}
private function faultHandler(event:FaultEvent, token:AsyncToken):void{
Alert.show(event.fault.faultString, event.fault.faultCode);
}
</mx:Script>
<mx:Button label="Get Data" click="getData()"/>
<mx:DataGrid dataProvider="{myData}"/>
</mx:Application>
Related examples in the same category