ASyncToken and IResponder in Flex
You want to call a set of Webservices one after another. A usual approach will be using result event of the first one to call the next one.
Well more better way of doing the same thing is using the Asynctocken and Responer interfaces which can track objects and pass parameters to the co-dependent services. Let’s have a sample.
For a demo purpose I am using following Dictionary Webservice.
http://services.aonaware.com/DictService/DictService.asmx
This Webservice gives an API for dictionary purpose. For quicker way, I am using wizard to call the webservice. Just add the wsdl and there you go.
Next step is to call the webservice function on creationComplete() event of the application.
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)">
private var dict : DictService = new DictService();
private var token:AsyncToken;
private var responder:mx.rpc.Responder;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
token = dict.DictionaryList();
responder = new mx.rpc.Responder(onResult, onFault)
token.addResponder(responder);
}
public function onResult(event:ResultEvent):void
{
}
public function onFault(event:FaultEvent):void
{
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:Application>
Advertisement
Categories: Action Script 3.0, Flex
ASyncToken, Flex, IResponder
