2009-06-27 76 views
4

寻找示例或文档链接以了解如何实现返回AsyncToken的方法。ActionScript 3 AsyncToken实现

请注意,这不是关于使用/使用返回AsyncToken的方法!我希望自己写这样的方法。

回答

2

是落实返回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; 
} 

请注意,你不能真正使用applyResultapplyFault方法,因为他们通过响应者Event,时除外结果响应者或故障对象。