apacheflex-我如何在Actionscript类中处理异步令牌



这是我的代码:

public class Schem
{
    public var info:String="";
    private var ro:RemoteObject = new RemoteObject("Hibernatetest");

    public function Schem()
    {       
        ro.endpoint = "http://jesus/blazeds/messagebroker/amf";
    }
    public function loadCurrentSchem():void
    {

        var token:AsyncToken = ro.getCells();
        token.addResponder(new AsyncResponder(onResult,onFault));
        info = info + "Loader Called ...";

    }
    private function onResult(event:ResultEvent,token:Object):void {
        var cellList:ArrayCollection = event.result as ArrayCollection;
        info = info + "Resulthandler Called";
    }
    private function onFault(event:FaultEvent,token:Object):void
    {
    }
    //Eventhandlers

    //Getters, Setters

}

通过检查infoString,我发现当我调用loadCurrentSchem()时,类没有到达Resulthanlder。为什么?

首先,我看不出异步令牌的优势在哪里?异步令牌是一种将有关单个查询及其状态的所有信息封装在单个对象中的模式。你可以在这里阅读更多。

在您的情况下,您所需要的只是获取查询结果事件。最好的方法是使用RemoteObject的事件(请参阅文档)。因此,代码将如下所示:

public class Schem
{
    public var info:String="";
    private var ro:RemoteObject;

    public function Schem()
    {
        ro = new RemoteObject("Hibernatetest");
        ro.endpoint = "http://jesus/blazeds/messagebroker/amf";
        ro.addEventListener(ResultEvent.RESULT, onResult);
        ro.addEventListener(FaultEvent.FAULT, onFault);
    }
    public function loadCurrentSchem():void
    {
        ro.getCells();
        info = info + "Loader Called ...";
    }
    private function onResult(event:ResultEvent):void {
        var cellList:ArrayCollection = event.result as ArrayCollection;
        info = info + "Resulthandler Called";
    }
    private function onFault(event:FaultEvent):void
    {
        info = info + "Errorhandler Called";
    }
    //Eventhandlers

    //Getters, Setters
}

相关内容

  • 没有找到相关文章

最新更新