Introduction to the use of Flex Async token Asynctoken

Source: Internet
Author: User

What is Asynctoken. The official documentation describes this: "This class provides a place for asynchronous RPC operations to set additional or token-level data." It also allows a iresponder to be attached as a standalone call. This asynctoken can be referenced in resultevent and faultevent with the token attribute. "
If you're unfamiliar with the nature of remote asynchronous calls in Flex, you're still a little confused. I met a lot of people unfamiliar with this handy class, so I tried to make it clear.
Whenever you use one of several external calls from your Flex/air app, you never know whether or when those calls return results (or errors), and you don't know the order in which they are returned. Even if you call remote objects in the order of "RO1", "RO2", "RO3", they may return in a different order. You may also wish to have different treatments for these results.
One way is to assign an asynchronous token (Asynctoken) to each call to track these calls.
Do not make remote calls like this:
Myro.myremotemethod ();
You should be like this:
var token:asynctoken=myro.myremotemethod ();(ensure import of Mx.rpc.AsyncToken)

Now there is a variable "token" that represents this individual invocation. Like this, you can assign token's own result and fault processing function
Token.addresponder (Myresponderclass);
Here the Myresponderclass class implements the Iresponder. Implementing Iresponder simply means defining the following two method signatures:
* Public Function result (data:object): void
* Public Function Fault (info:object): void
So you can set the result and fault handler on your remote call when you call, instead of putting hard coding into your remote object, Httpservice, or webservice tag. This is exactly how Cairngorm and other micro architectures work.
The last cool feature of Asynctoken is that it is a dynamic class. This means that when you make a remote call, you can add attributes to the token, and then read the properties in the Result/fault handler.

In addition, there is callresponder in Flex sdk3.4, which can be referenced with the token property of the Callresponder instance. In the flex sdk3.2 Chinese do not have this class, if you want to use the words can only write their own, as long as this class inherits from the Iresponder interface can be

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.