actionscript-3 - ActionScript 3 AsyncToken 实现

标签 actionscript-3 asynctoken

寻找有关如何实现返回 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;
}

请注意,您实际上不能使用 applyResultapplyFault方法,因为它们向响应者传递了 Event ,当响应者除了结果或故障对象。

关于actionscript-3 - ActionScript 3 AsyncToken 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1052858/

相关文章:

actionscript-3 - AS3 - 是否可以按对象属性搜索数组?

java - 弹性 : LCDS Service returning null Asynctoken when executed 2nd time

java - FLEX - 将 AsyncToken 转换为 ArrayCollection

flash - 调用 example Function() 和 example Function.call() 有什么区别?

flash - 访问 AS3 中的 Document 类

actionscript-3 - 将多个图像添加到多个正文

actionscript-3 - 为什么在按下鼠标中键时不发送 MOUSE_MOVE 事件?