首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActionScript 3 AsyncToken实现

ActionScript 3 AsyncToken实现
EN

Stack Overflow用户
提问于 2009-06-27 13:48:18
回答 2查看 1.8K关注 0票数 4

查找有关如何实现返回AsyncToken的方法的示例或文档链接。

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-10-22 01:41:10

实现一个返回AsyncToken的方法很简单:

代码语言:javascript
复制
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方法,因为当响应器不包含result或Event对象时,它们会向响应器传递一个错误。

票数 2
EN

Stack Overflow用户

发布于 2009-12-26 17:10:58

Swiz框架的TestUtil类有一些非常酷的方法来模拟AsyncToken行为:

http://code.google.com/p/swizframework/source/browse/trunk/src/main/flex/org/swizframework/util/TestUtil.as

Brian Kotek有一篇内容非常丰富的博客文章,介绍了如何使用它来使用模拟委托来模拟服务器调用:

http://www.briankotek.com/blog/index.cfm/2009/3/16/Swiz-Part-5-Simulating-Server-Calls-with-a-mock-AsyncToken

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1052858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档