zoukankan      html  css  js  c++  java
  • flex flashplayer 程序 和 air 程序 通过 LocalConnection 通信

    flashplayer 做控制端:

    <?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" creationComplete="init(event)">
        <fx:Script>
            <![CDATA[
                import mx.events.FlexEvent;
                
                
                private var conn:LocalConnection;
                
                protected function init(event:FlexEvent):void
                {
                    conn = new LocalConnection;
                    conn.addEventListener(StatusEvent.STATUS,statusHandler);                
                }
                
                private function statusHandler(evt:StatusEvent):void
                {
                    switch (evt.level) {
                        case "status":
                            trace("LocalConnection.send() succeeded");
                            break;
                        case "error":
                            trace("LocalConnection.send() failed");
                            break;
                    }
                }
                
                protected function pressedHandler(event:MouseEvent):void
                {
                    var obj:Object = {name:txt.text,age:30};
                    conn.send('_connectionName3','methodName',obj);                
                }
                
            ]]>
        </fx:Script>
        <s:layout>
            <s:VerticalLayout/>
        </s:layout>
        <s:TextInput id="txt"/>
        <s:Button label="test" click="pressedHandler(event)"/>
    </s:Application>

    air 做客户端:

    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                           xmlns:s="library://ns.adobe.com/flex/spark" 
                           xmlns:mx="library://ns.adobe.com/flex/mx" close="windowedapplication1_closeHandler(event)"
                           creationComplete="init(event)">
        <fx:Script>
            <![CDATA[
                import mx.controls.Alert;
                import mx.events.FlexEvent;
                
                private var conn:LocalConnection;
                
                protected function init(event:FlexEvent):void
                {
                    conn = new LocalConnection;
                    conn.client = this;
                    
                    conn.allowDomain("*");
                    
                    try {
                        conn.connect('_connectionName3');
                        conn.addEventListener(StatusEvent.STATUS,statusHandler);
                    } catch (error:ArgumentError) {
                        trace("Can't connect...the connection name is already being used by another SWF");
                    }
                }
                
                private function statusHandler(evt:StatusEvent):void
                {
                    switch (evt.level) {
                        case "status":
                            trace("LocalConnection.send() succeeded");
                            break;
                        case "error":
                            trace("LocalConnection.send() failed");
                            break;
                    }
                }
                
                public function methodName(param:Object):void
                {
                    if(param)
                    {
                        Alert.show("姓名:" + param.name);
                    }
                }
                
                protected function windowedapplication1_closeHandler(event:Event):void
                {
                    if (conn)
                        conn.close();
                }
                
            ]]>
        </fx:Script>
        
    </s:WindowedApplication>

     client 对象绑定的对象可以是动态或普通类,其中中要访问的方法一定要是public的,或者直接绑定的类似这样:

    conn.client = {methodName:function(o:Object):void{
      Alert.show(o.name);
    }};

  • 相关阅读:
    被放弃的概率权,机器下围棋不理会沉没成本
    百位性感女明星三围大曝光,体型测试设计
    斯坦福大学机器学习,EM算法求解高斯混合模型
    Javascript图片预加载详解
    使用马尔可夫模型自动生成文章
    18种女粉引流方法、效果、评估
    既然认准了这条路,就不必打听要走多久!
    新媒体运营10个大坑,思维导图版
    谷歌发布"自动机器学习"技术 AI可自我创造
    Centos7下PHP的卸载与安装nginx
  • 原文地址:https://www.cnblogs.com/xuezizhenchengxuyuan/p/5647237.html
Copyright © 2011-2022 走看看