Yes, that is how I normally use AsyncToken.  You should know though that it
also provides for directly assigning handler/callback functions if you
prefer that style.

 

Tracy Spratt,

Lariat Services, development services available

  _____  

From: [email protected] [mailto:[email protected]] On
Behalf Of valdhor
Sent: Wednesday, November 25, 2009 11:05 AM
To: [email protected]
Subject: [SPAM] [flexcoders] Re: Questions I always wanted to know the
answers to - AsyncTokens

 

  

Using an AsyncToken allows you to have only one event listener and one
function to handle all responses from a remote procedure call. You add
some data to the AsyncToken and when the call returns you can check what
the data was and use that to run different code. For example:

myService = new RemoteObject("myDestination");
myService.addEventListener(ResultEvent.RESULT, resultHandler);

var myToken:AsyncToken = myService.getPeople();
myToken.data = "getPeople";
myToken.myService.getPlaces();
myToken.data = "getPlaces";

private function resultHandler(event:ResultEvent):void
{
switch(event.token.data)
{
case "getPeople":
// Do the stuff for getPeople
break;
case "getPlaces":
// Do the stuff for getPlaces
break;
}
}

So, if you have a separate event listener and function for each call you
make, then Flex will work just as well. It is just a different way to do
things.

Also note that data can be anything you want like an object or whatever.

--- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com,
"Wally Kolcz" <wko...@...> wrote:
>
> What is AsyncToken and why is it preferred over just calling the
Remote Object's method and adding listeners to the method for the result
and fault?
>
> "This class provides a place to set additional or token-level data for
> asynchronous RPC operations. It also allows an IResponder to be
attached
> for an individual call." What is an example of why you would need to
attach the IReponder (addResponser) to a particular method call?
>
> Again, I see on another site this "In you application you have
multiple service calls happening at the
> same time and you need to know which data coming back belongs to which
> call.". Calling the same method/service (getPeople) multiple times in
the same instance or just calling multiple methods (getPeople,
getPlaces, getThings) at the same time? I never had a problem with Flex
mixing up the results of multiple methods being called before as a view
loads up..
>
> Thanks for any info you can provide.
>



Reply via email to