Hee is some sample code that demonstates one way to use AsyncToken.
Tracy
Sample code using HTTPService, e4x, handler function to populate a list item.  
Also shows usage of AsyncToken.

The DataGrid tag:
<mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


The HTTPService tag:
<mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" 
fault="..../>

Script block declaration:
import mx.rpc.Events.ResultEvent;
[Bindable]private var _xlcMyListData:XMLListCollection;

Invoke send:
var oRequest:Object = new Object();
oRequest.Arg1 = "value1";
var callToken:AsyncToken = service.send(oRequest);
token.callId = "myQuery1";

Result Handler function:
private function onResult(oEvent:ResultEvent):void  {
  var xmlResult:XML = XML(event.result);                //converts result 
Object to XML. can also use "as" operator
  var xlMyListData:XMLList = xmlResult.myListData;      //depends on xml 
format, is row data
  _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a 
collection
  trace(_xlcMyListData.toXMLString());                  //so you can see 
exactly how to specify dataField or build labelFunction
  var callToken:AsyncToken = oEvent.token;
  var sCallId = callToken.callId;                       //"myQuery1"
  switch(sCallId)  {                                    //Process the result 
conditionally
    case "myQuery1":
      doQuery2();                                       //do whatever. this 
example calls another data service query
      break;
    ... 
  }
}//onResult

________________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Tracy 
Spratt
Sent: Wednesday, November 28, 2007 1:52 PM
To: [email protected]
Subject: RE: [flexcoders] Re: HttpService not called the first time

Data retrieval is very fast.  The speed difference should be negligible.  
Regarding performance, focus on optimizing the rendering, which is the 
bottleneck.
 
Tracy
 
________________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of gers32
Sent: Wednesday, November 28, 2007 2:47 AM
To: [email protected]
Subject: [flexcoders] Re: HttpService not called the first time
 
Hi Tracy,

That's a good idea. Now, I'm wondering what the trade off is between
one HttpService per Component (bigger SWF file size, but parallel
requests thus faster data access on multi-processor boxes?) and one
single HttpService for the whole application (smaller SWF file, but
sequential thus slower data retrieval?).

I'd appreciate an example using AsyncToken, if you have one.

Thanks,

Chris.

--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> Note that you really need only a single instance of HTTPService. You
> can set the url, method, etc and build the request object using AS, and
> can handle the result conditionally using AsyncToken.
> 
> 
> 
> Post if you need examples.
> 
> 
> 
> Tracy
 

Reply via email to