0

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: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?

Kai
  • 376
  • 1
  • 4
  • 17

1 Answers1

0

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
}
Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • I know of the solution you described. I cant use it, because while the remoteobjects gets its data, the remaining code gets executed. With an asynctoken the execution gets delayed until the data arrives - thats why i use it. On the other hand i would like to see the problem solved, because the code above works just fine in the script tags, but in a separate class it doesnt. – Kai May 26 '11 at 11:33
  • Hm. Its seems to me you don't understand Flash Player code flow model clearly. The point is that both ways are absolutely equivalent from the code execution point of view and they are both asynchronous. Please describe what do you mean as "the remoteobjects gets its data, the remaining code gets executed. With an asynctoken the execution gets delayed until the data arrives". – Constantiner May 26 '11 at 11:38
  • This may very well be the case. And i would be glad if you taught me. :)So: Heres the situation. I have a some java-objects, which i serialize and get per remoteobject. These are basically data objects. From these data-objects a DisplayObject (UI Component) is created in runtime. Now i had it working with simple remoteobject - Handlers, but a problem emerged: The player created the Displayobject, without having received the complete data-object. I thought asynctoken might be a solution to this. Maybe im wrong? – Kai May 26 '11 at 12:16
  • Yes, you're wrong. The problem isn't related the way remote object results handling (I mean using async token or events) as far as the result is asynchronous in both cases. I suppose the problem is in your GUI logic. I suppose SO is the right place to ask a question about it :) – Constantiner May 26 '11 at 12:21
  • Ok, i will present my code as soon as i get home to my workstation. Thx! – Kai May 26 '11 at 12:24