ActionScriptの3のAsyncToken実装
-
20-08-2019 - |
質問
のAsyncTokenを返すメソッドを実装する方法についての例やドキュメントのリンクを探しています。
これは/使用方法のAsyncTokenを返すの消費に関するものではありません注意してください!私はこのような方法を自分で書きたいと思います。
解決
のAsyncTokenを返すメソッドを実装することは簡単である:
function doStuffLater():AsyncToken {
var token:AsyncToken = new AsyncToken(null);
// This method will randomly call the responder's 'result' or 'fault'
// handler.
function doStuff() {
var response:String = (Math.random() > 0.5)? "result" : "fault";
for each (responder:IResponder in (token.responders || [])) {
// rememeber: this is equivilent to
// responder.result(...) or responder.fault(...)
responder[response]("Got a result!");
}
}
setTimeout(doStuff, 1000);
return token;
}
彼らは、applyResult
レスポンダを渡すので、あなたが実際に、applyFault
とEvent
メソッドを使用できないことに注意してください時に結果や障害物を除いて、レスポンダます。
他のヒント
期待外れの枠組みのTestUtilクラスはAsyncTokenです行動をあざけるためにいくつかの本当にクールな方法があります:
<のhref = "http://code.google.com/p/swizframework/source/browse/trunk/src/main/flex/org/swizframework/util/TestUtil.as" のrel = "nofollowをnoreferrer" > http://code.google.com/p/swizframework/source/browse/trunk/src/main/flex/org/swizframework/util/TestUtil.as の
ブライアンKotekはモックデリゲートを使用して、サーバーの呼び出しをシミュレートするためにそれを使用する方法について非常に有益ブログの記事があります:
<のhref = "http://www.briankotek.com/blog/index.cfm/2009/3/16/Swiz-Part-5-Simulating-Server-Calls-with-a-mock-AsyncToken" rel = "nofollowをnoreferrer"> http://www.briankotek.com/blog/index.cfm/2009/3/16/Swiz-Part-5-Simulating-Server-Calls-with-a-mock-AsyncToken