如何在外部类中实现RemoteObject?

| 这是代码:
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
}
不幸的是,当我调用loadCurrentSchem()函数时,它没有到达eventHandler。怎么了? 这就是我所说的课:
<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>
那里。     
已邀请:
        问题是您没有正确确保结果处理程序正确调用。问题是,当您使用:
textfeld.text = schem.info;
您已设置以下值:
info = info + \"Loader called ... \\n\";
作为文本字段的文本,并且该值在结果处理程序中不会更改。 您可以通过至少两种方式解决此问题: 从
EventDispatcher
扩展
Schem
类,并将事件元数据放在此处。 班级:
[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
}
然后在您的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;

        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>
第二种方法是使用数据绑定。
Schem
班:
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
}
在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}\" />
希望这可以帮助! :)     

要回复问题请先登录注册