1

Heres the code:

public class Schem
{
    public var info:String="";      

    public function Schem()
    {
    }

    public function loadCurrentSchem():void
    {
        var ro:RemoteObject = new RemoteObject("Hibernatetest");
        ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
        ro.addEventListener(ResultEvent.RESULT,onResult);
        ro.getCells();
        info = info + "Loader called ... \n";




    }

    public function onResult(event:ResultEvent):void
    {
        var array:ArrayCollection = event.result as ArrayCollection;
        info = info + "Schemlength = " + String(array.length)+ "\n";
    }


    private function onFault(event:FaultEvent):void
    {
        info = info + "Errorhandler Called";
    }
    //Eventhandlers


    //Getters, Setters
}

Unfortunatly, its doesnt reach the eventHandler, when i call the loadCurrentSchem() function. Whats wrong?

This is how i call the class:

<fx:Script>
    <![CDATA[
        import argoseye.main.Golem;
        import argoseye.main.Schem;

        import mx.collections.ArrayCollection;
        import mx.rpc.AsyncToken;
        import mx.rpc.Responder;
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.remoting.RemoteObject;

        protected function button1_clickHandler(event:MouseEvent):void
        {
            var schem:Schem = new Schem();
            schem.loadCurrentSchem();
            textfeld.text = schem.info;
        }

    ]]>
</fx:Script>

There.

Kai
  • 376
  • 1
  • 4
  • 17
  • Are you sure your endpoint is getting hit? – Jason Towne May 27 '11 at 17:35
  • Yes I am. For two reasons. First: This very code works in the application script-tag perfectly, and second: The BlazeDS Console counts an successfull call. – Kai May 27 '11 at 17:41
  • Did you tried to subscribe to the `fault` event too? Maybe result handler doesn't invoke because of some fault which you doesn't listen at all? – Constantiner May 27 '11 at 17:57
  • Just did it, and, as expected, nothing. I dont understand the difference...it should work in a serpate class, to, shouldnt it? – Kai May 27 '11 at 18:00
  • In future use debugger breakpoints or `trace()` statements to make sure some method is calling or not :) – Constantiner May 27 '11 at 20:00

1 Answers1

0

The problem is you haven't proper made sure the result handler called correctly. The thing is that when you use:

textfeld.text = schem.info;

you've set the value of:

info = info + "Loader called ... \n";

as a text of the text field and this value isn't changed in a result handler.

You can resolve this issue at least two ways:

  • Extend your Schem class from EventDispatcher and place events metadata there.

The class:

[Event(name="result", type="mx.rpc.events.ResultEvent")]
[Event(name="fault", type="mx.rpc.events.FaultEvent")]
public class Schem extends EventDispatcher
{
    public var info:String="";      

    public function Schem()
    {
    }

    public function loadCurrentSchem():void
    {
        var ro:RemoteObject = new RemoteObject("Hibernatetest");
        ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
        ro.addEventListener(ResultEvent.RESULT,onResult);
        ro.addEventListener(FaultEvent.FAULT,onFault);
        ro.getCells();
        info += "Loader called ... \n";




    }

    private function onResult(event:ResultEvent):void
    {
        var array:ArrayCollection = event.result as ArrayCollection;
        info += "Schemlength = " + String(array.length)+ "\n";
        dispatchEvent(event);
    }


    private function onFault(event:FaultEvent):void
    {
        info += "Errorhandler Called";
        dispatchEvent(event);
    }
    //Eventhandlers


    //Getters, Setters
}

Then in your MXML class:

<fx:Script>
    <![CDATA[
        import argoseye.main.Golem;
        import argoseye.main.Schem;

        import mx.collections.ArrayCollection;
        import mx.rpc.AsyncToken;
        import mx.rpc.Responder;
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.remoting.RemoteObject;

        protected function button1_clickHandler(event:MouseEvent):void
        {
            var schem:Schem = new Schem();
            schem.addEventListener(ResultEvent.RESULT,onResult);
            schem.addEventListener(FaultEvent.FAULT,onFault);
            schem.loadCurrentSchem();
            textfeld.text = schem.info;

        }

    private function onResult(event:ResultEvent):void
    {
        textfeld.text = event.currentTarget.info;
    }

    private function onFault(event:FaultEvent):void
    {
        textfeld.text = event.currentTarget.info;
    }
    ]]>
</fx:Script>
  • The second way is to use data binding.

Schem class:

public class Schem
{
    [Bindable]
    public var info:String="";      

    public function Schem()
    {
    }

    public function loadCurrentSchem():void
    {
        var ro:RemoteObject = new RemoteObject("Hibernatetest");
        ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
        ro.addEventListener(ResultEvent.RESULT,onResult);
        ro.addEventListener(FaultEvent.FAULT,onFault);
        ro.getCells();
        info += "Loader called ... \n";
    }

    private function onResult(event:ResultEvent):void
    {
        var array:ArrayCollection = event.result as ArrayCollection;
        info += "Schemlength = " + String(array.length)+ "\n";
    }


    private function onFault(event:FaultEvent):void
    {
        info += "Errorhandler Called";
    }
    //Eventhandlers


    //Getters, Setters
}

And in MXML:

<fx:Script>
    <![CDATA[
        import argoseye.main.Golem;
        import argoseye.main.Schem;

        import mx.collections.ArrayCollection;
        import mx.rpc.AsyncToken;
        import mx.rpc.Responder;
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.remoting.RemoteObject;

        [Bindable]
        private var schem:Schem;

        protected function button1_clickHandler(event:MouseEvent):void
        {
            schem = new Schem();
            schem.loadCurrentSchem();
        }

    ]]>
</fx:Script>
<s:Label id="textfeld" text="{schem.info}" />

Hope this helps! :)

Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • It helped indeed. Using your method i found out that my class acts quite functional and the problem is passing the results to other classes. I will try a different approach to do this. (Binding) – Kai May 28 '11 at 00:05