尋找示例或文檔鏈接以瞭解如何實現返回AsyncToken的方法。ActionScript 3 AsyncToken實現
請注意,這不是關於使用/使用返回AsyncToken的方法!我希望自己寫這樣的方法。
尋找示例或文檔鏈接以瞭解如何實現返回AsyncToken的方法。ActionScript 3 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
,時除外結果響應者或故障對象。
Swiz會框架的TestUtil類有嘲諷的AsyncToken行爲的一些很酷的方式:
布賴恩鐵克對如何使用它使用模擬委託給模擬服務器調用一個非常翔實的博客文章: