开发者

How do i handle Asynctokens in Actionscript classes

开发者 https://www.devze.com 2023-03-08 17:41 出处:网络
Heres my code: public class Schem { public var info:String=\"\"; private var ro:RemoteObject = new RemoteObject(\"Hibernatetest\");

Heres my code:

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开发者_Go百科:FaultEvent,token:Object):void
    {

    }
    //Eventhandlers


    //Getters, Setters


}

By inspecting the info String i found out, that the class doesnt reach the Resulthanlder, when i call loadCurrentSchem(). Why is that?


First of all I can't see where you have advantages of async token? Async token is a pattern to incapsulate all the information about a single query and its state in a single object. You can read more here.

In your case all that you need is to get query result event. The best way to do that is to use RemoteObject's events (see documentation). So the code will look like the following:

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号