如何在纯 AS3 应用程序中创建 RemoteService

发布于 2024-10-31 00:04:57 字数 86 浏览 1 评论 0原文

我想从我的纯 AS3 应用程序进行远程服务调用。 对于纯 AS3,RemoteObject 类不可用。 有谁可以帮我解决一下。

谢谢, 苏德什

I want to make a remote service call from my pure AS3 application.
In the case of Pure AS3 the RemoteObject class is unavailable.
Does any one can help me with a solution.

Thanks,
Sudesh

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

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

发布评论

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

评论(2

南…巷孤猫 2024-11-07 00:04:57

这是我为此编写的一个课程。我在每个项目中都使用它,所以我不必再考虑它了。

public class ServiceCaller extends EventDispatcher
{
    private static var s__instance:ServiceCaller;

    private var m__netConnection:NetConnection;

    public function ServiceCaller() 
    {
        var l__tempConnection:NetConnection = new NetConnection();
        l__tempConnection.objectEncoding = ObjectEncoding.AMF3;
        m__netConnection = new NetConnection();
        m__netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        m__netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        m__netConnection.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);       
    }

    public function connect(i__url:String):void
    {           
        m__netConnection.connect(Model.instance.config.gatewayUrl); 
    }

    private function netStatusHandler(i__event:NetStatusEvent):void 
    {
        trace(i__event.info.code);
    }

    private function statusHandler(i__object:Object):void
    {
        for (var l__key:String in i__object)
            trace(l__key, i__object[l__key]);
        CursorManager.removeBusyCursor();
    }

    private function securityErrorHandler(i__event:SecurityErrorEvent):void 
    {
        throw new Error("securityErrorHandler: " + i__event.toString());
    }

    private function ioErrorHandler(i__event:IOErrorEvent):void 
    {
        throw new Error("ioErrorHandler: " + i__event.toString());
    }

    public function callService(i__name:String, i__listener:Function, ...arguments):void
    {
        m__netConnection.call.apply(m__netConnection, [i__name, new Responder(i__listener, statusHandler)].concat(arguments));
    }


    static public function get instance():ServiceCaller 
    {           
        if (!s__instance)
            s__instance = new ServiceCaller();
        return s__instance; 
    }

    static public function set instance(value:ServiceCaller):void 
    {
        s__instance = value;
    }

}

要使用它,您必须首先调用一次 ServiceCaller.instance.connect("gatewayURL");,然后每次需要调用时:

ServiceCaller.instance.callService("serviceName", onResult, param1, param2);

onResult 是一个回调函数获取结果作为参数。您可以根据服务需要添加任意数量的参数。

Here is a class I wrote for this. I use it on every project so I don't have to think about it any more.

public class ServiceCaller extends EventDispatcher
{
    private static var s__instance:ServiceCaller;

    private var m__netConnection:NetConnection;

    public function ServiceCaller() 
    {
        var l__tempConnection:NetConnection = new NetConnection();
        l__tempConnection.objectEncoding = ObjectEncoding.AMF3;
        m__netConnection = new NetConnection();
        m__netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        m__netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        m__netConnection.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);       
    }

    public function connect(i__url:String):void
    {           
        m__netConnection.connect(Model.instance.config.gatewayUrl); 
    }

    private function netStatusHandler(i__event:NetStatusEvent):void 
    {
        trace(i__event.info.code);
    }

    private function statusHandler(i__object:Object):void
    {
        for (var l__key:String in i__object)
            trace(l__key, i__object[l__key]);
        CursorManager.removeBusyCursor();
    }

    private function securityErrorHandler(i__event:SecurityErrorEvent):void 
    {
        throw new Error("securityErrorHandler: " + i__event.toString());
    }

    private function ioErrorHandler(i__event:IOErrorEvent):void 
    {
        throw new Error("ioErrorHandler: " + i__event.toString());
    }

    public function callService(i__name:String, i__listener:Function, ...arguments):void
    {
        m__netConnection.call.apply(m__netConnection, [i__name, new Responder(i__listener, statusHandler)].concat(arguments));
    }


    static public function get instance():ServiceCaller 
    {           
        if (!s__instance)
            s__instance = new ServiceCaller();
        return s__instance; 
    }

    static public function set instance(value:ServiceCaller):void 
    {
        s__instance = value;
    }

}

To use it, you have first to call once ServiceCaller.instance.connect("gatewayURL"); and then each time you want a call:

ServiceCaller.instance.callService("serviceName", onResult, param1, param2);

onResult is a callback function taht gets the result as a parameter. You can add as many parameters as your service needs.

旧故 2024-11-07 00:04:57

只需使用 flash.net.NetConnection ...检查 call() 方法以及 flash.net.Responder 类。

Just use flash.net.NetConnection ... check the call() method and also the flash.net.Responder class.

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