如何通过 AsyncToken 处理远程方法调用?

发布于 2024-11-09 21:55:43 字数 3608 浏览 4 评论 0原文

所以这是我想要工作的 mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

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

            import mx.collections.ArrayCollection;
            import mx.rpc.AsyncResponder;
            import mx.rpc.AsyncToken;
            import mx.rpc.Responder;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.InvokeEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.remoting.RemoteObject;
            protected function button1_clickHandler(event:MouseEvent):void
            {
                var ro:RemoteObject = new RemoteObject("destination");
                ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
                ro.addEventListener(InvokeEvent.INVOKE,onInvoke);

                var token:AsyncToken = new AsyncToken();
                token.addResponder(new AsyncResponder(onResult,onFault));

                token = ro.getCells();
                textfeld.text = textfeld.text + "Clickhandler called .... \n";

            }

            public function onResult(event:ResultEvent,token:Object):void {
                textfeld.text = textfeld.text + "Resulthandler called .... \n";
                var cellList:ArrayCollection = event.result as ArrayCollection;

            }

            public function onFault(event:FaultEvent,token:Object):void
            {
                textfeld.text = textfeld.text + "Faulthandler called .... \n";
            }

            public function onInvoke(event:InvokeEvent):void {
                textfeld.text = textfeld.text + "Invokehandler called .... \n";
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button x="1093" y="575" label="Button" click="button1_clickHandler(event)"/>
    <s:TextArea x="1022" y="183" id="textfeld"/>
</s:Application>

输出是

调用处理程序调用 ....

点击处理程序调用....

Resulthandler 不会被调用。我做错了什么?

编辑:我尝试将过程导出到一个类中,该类应该管理这些事情。

package argoseye.main

{ 导入 flash.events.Event;

import mx.collections.ArrayCollection;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.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";

        var token:AsyncToken = ro.getCells();
        token.addResponder(new AsyncResponder(onResult,onFault));

        info = info + "Loader Called ...";


    }

    public function onResult(event:ResultEvent,token:Object):void {
        var cellList:ArrayCollection = event.result as ArrayCollection;
        info = info + "Resulthandler Called";

    }

    public function onFault(event:FaultEvent,token:Object):void
    {

    }
    //Eventhandlers


    //Getters, Setters


}

如果我调用它

,它不会到达事件处理程序。我的错误在哪里?

So here is the mxml i would like to get working:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

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

            import mx.collections.ArrayCollection;
            import mx.rpc.AsyncResponder;
            import mx.rpc.AsyncToken;
            import mx.rpc.Responder;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.InvokeEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.remoting.RemoteObject;
            protected function button1_clickHandler(event:MouseEvent):void
            {
                var ro:RemoteObject = new RemoteObject("destination");
                ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
                ro.addEventListener(InvokeEvent.INVOKE,onInvoke);

                var token:AsyncToken = new AsyncToken();
                token.addResponder(new AsyncResponder(onResult,onFault));

                token = ro.getCells();
                textfeld.text = textfeld.text + "Clickhandler called .... \n";

            }

            public function onResult(event:ResultEvent,token:Object):void {
                textfeld.text = textfeld.text + "Resulthandler called .... \n";
                var cellList:ArrayCollection = event.result as ArrayCollection;

            }

            public function onFault(event:FaultEvent,token:Object):void
            {
                textfeld.text = textfeld.text + "Faulthandler called .... \n";
            }

            public function onInvoke(event:InvokeEvent):void {
                textfeld.text = textfeld.text + "Invokehandler called .... \n";
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button x="1093" y="575" label="Button" click="button1_clickHandler(event)"/>
    <s:TextArea x="1022" y="183" id="textfeld"/>
</s:Application>

The output is

Invokehandler called ....

Clickhandler called ....

The Resulthandler doesnt get called, allthough the BlazeDS Console registers an successfull Resultevent. What do I do wrong?

Edit: I tried exporting the procedure into a class, which is supposed to manage these things.

package argoseye.main

{
import flash.events.Event;

import mx.collections.ArrayCollection;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.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";

        var token:AsyncToken = ro.getCells();
        token.addResponder(new AsyncResponder(onResult,onFault));

        info = info + "Loader Called ...";


    }

    public function onResult(event:ResultEvent,token:Object):void {
        var cellList:ArrayCollection = event.result as ArrayCollection;
        info = info + "Resulthandler Called";

    }

    public function onFault(event:FaultEvent,token:Object):void
    {

    }
    //Eventhandlers


    //Getters, Setters


}

}

If i call it, it doesnt reach the eventhandler. Where is my mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的憧憬 2024-11-16 21:55:43

您的错误在于以下几行:

var token:AsyncToken = new AsyncToken();
token.addResponder(new AsyncResponder(onResult,onFault));
token = ro.getCells();

您正在第 1 行创建一个新令牌。
您在第 2 行指定一个响应者。
然后您在第 3 行重新分配令牌。

您在第 3 行所做的实际上是创建一个新令牌,因此它没有附加响应程序,因为它是一个新实例。

所以应该是:

var token:AsyncToken = ro.getCells(); 
//ro.getCells() will return a new instance of AsyncToken
token.addResponder(new AsyncResponder(onResult,onFault));

Your error lies in these lines:

var token:AsyncToken = new AsyncToken();
token.addResponder(new AsyncResponder(onResult,onFault));
token = ro.getCells();

You're creating a new token on line 1.
You assign a responder on line 2.
And then you reassign the token on line 3.

What you do on line 3 is effectively creating a new token, thus it doesn't have the responder attached to it, because it's a new instance.

So it should be:

var token:AsyncToken = ro.getCells(); 
//ro.getCells() will return a new instance of AsyncToken
token.addResponder(new AsyncResponder(onResult,onFault));
淡紫姑娘! 2024-11-16 21:55:43

使用以下代码:

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

        import mx.collections.ArrayCollection;
        import mx.rpc.AsyncResponder;
        import mx.rpc.AsyncToken;
        import mx.rpc.Responder;
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.InvokeEvent;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.remoting.RemoteObject;
        protected function button1_clickHandler(event:MouseEvent):void
        {
            var ro:RemoteObject = new RemoteObject("destination");
            ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
            ro.addEventListener(InvokeEvent.INVOKE,onInvoke);

            var token:AsyncToken = ro.getCells();
            token.addResponder(new AsyncResponder(onResult,onFault));
            textfeld.text = textfeld.text + "Clickhandler called .... \n";

        }

        public function onResult(event:ResultEvent,token:Object):void {
            textfeld.text = textfeld.text + "Resulthandler called .... \n";
            var cellList:ArrayCollection = event.result as ArrayCollection;

        }

        public function onFault(event:FaultEvent,token:Object):void
        {
            textfeld.text = textfeld.text + "Faulthandler called .... \n";
        }

        public function onInvoke(event:InvokeEvent):void {
            textfeld.text = textfeld.text + "Invokehandler called .... \n";
        }
    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button x="1093" y="575" label="Button" click="button1_clickHandler(event)"/>
<s:TextArea x="1022" y="183" id="textfeld"/>

Use the following code:

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

        import mx.collections.ArrayCollection;
        import mx.rpc.AsyncResponder;
        import mx.rpc.AsyncToken;
        import mx.rpc.Responder;
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.InvokeEvent;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.remoting.RemoteObject;
        protected function button1_clickHandler(event:MouseEvent):void
        {
            var ro:RemoteObject = new RemoteObject("destination");
            ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
            ro.addEventListener(InvokeEvent.INVOKE,onInvoke);

            var token:AsyncToken = ro.getCells();
            token.addResponder(new AsyncResponder(onResult,onFault));
            textfeld.text = textfeld.text + "Clickhandler called .... \n";

        }

        public function onResult(event:ResultEvent,token:Object):void {
            textfeld.text = textfeld.text + "Resulthandler called .... \n";
            var cellList:ArrayCollection = event.result as ArrayCollection;

        }

        public function onFault(event:FaultEvent,token:Object):void
        {
            textfeld.text = textfeld.text + "Faulthandler called .... \n";
        }

        public function onInvoke(event:InvokeEvent):void {
            textfeld.text = textfeld.text + "Invokehandler called .... \n";
        }
    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button x="1093" y="575" label="Button" click="button1_clickHandler(event)"/>
<s:TextArea x="1022" y="183" id="textfeld"/>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文