发送方AIR程序:

package
{
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import flash.text.TextField; /**
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2016-10-11 下午2:34:17
*
*/
public class Sender extends Sprite
{
private var _lc:LocalConnection;
private var _sendBtn:TextField;
private var _logTxt:TextField;
private var _inputTxt:TextField;
public function Sender()
{
initInput();
initLog();
_lc = new LocalConnection();
_lc.addEventListener(StatusEvent.STATUS, onStatus);
_sendBtn = getTextButton(this,"-send->>",412,10,60,20);
_sendBtn.addEventListener(MouseEvent.CLICK,onSend);
}
private function onSend(e:MouseEvent):void
{
_lc.send("app#receiver:AIR_TO_AIR","senderMethod",_inputTxt.text);
}
private function onStatus(event:StatusEvent):void
{
switch (event.level)
{
case "status" :
log("LocalConnection.send() succeeded");
break;
case "error" :
log("LocalConnection.send() failed");
break;
}
}
private function initInput():void
{
_inputTxt = new TextField();
_inputTxt.type = "input";
_inputTxt.border = true;
_inputTxt.x = 10;
_inputTxt.y = 10;
_inputTxt.width = 400;
_inputTxt.height = 20;
_inputTxt.text = "";
this.addChild(_inputTxt); }
private function initLog():void
{
_logTxt = new TextField();
_logTxt.width = 450;
_logTxt.height = 300;
_logTxt.border = true;
_logTxt.x = 10;
_logTxt.y = 40;
this.addChild(_logTxt);
}
private function log(msg:String=""):void
{
_logTxt.appendText(msg+"\n");
}
public static function getTextButton(parent:DisplayObjectContainer,text:String,x:Number,y:Number,width:Number,height:Number):TextField
{
var button:TextField = new TextField();
button.autoSize = "center";
button.width = width;
button.height = height;
button.selectable = false;
button.border = true;
button.htmlText = "<a href='event:#'>"+text+"</a>";
button.x = x;
button.y = y;
parent.addChild(button);
return button; }
}
}

接收方AIR程序:

package
{
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import flash.text.TextField; /**
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2016-10-11 下午2:34:54
*
*/
public class Receiver extends Sprite
{
private var _sendBtn:TextField;
private var _lc:LocalConnection;
private var _logTxt:TextField; public function Receiver()
{
initLog();
_lc = new LocalConnection();
_lc.client = this;
_lc.allowDomain("app#Sender");
try
{
_lc.connect("AIR_TO_AIR");
}
catch (error:ArgumentError)
{
log("Can't connect...the connection name is already being used by another SWF");
} }
private function initLog():void
{
_logTxt = new TextField();
_logTxt.width = 450;
_logTxt.height = 300;
_logTxt.border = true;
_logTxt.x = 10;
_logTxt.y = 40;
this.addChild(_logTxt);
}
private function log(msg:String=""):void
{
_logTxt.appendText(msg+"\n");
}
public function senderMethod(param:String):void
{
log(param);
} }
}

需要注意的是,发送方send函数中传入的函数名"senderMethod",在接收方程序中的必须设置为公开(public)的方法,否则会出错:

Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.LocalConnection was unable to invoke callback senderMethod. error=ReferenceError: Error #1069: Property senderMethod not found on Receiver and there is no default value.
参考:http://www.cnblogs.com/frost-yen/p/5301779.html

还发现个有趣的是:传入的应用程序 ID可以不区分大小写,"app#receiver:AIR_TO_AIR"中的receiver

[ActionScript 3.0] 两个AIR之间的通信示例LocalConnection的更多相关文章

  1. Android中两个Activity之间简单通信

    在Android中,一个界面被称为一个activity,在两个界面之间通信,采用的是使用一个中间传话者(即Intent类)的模式,而不是直接通信. 下面演示如何实现两个activity之间的通信. 信 ...

  2. 基于WSAAsyncSelect模型的两台计算机之间的通信

    任务目标 编写Win32程序模拟实现基于WSAAsyncSelect模型的两台计算机之间的通信,要求编程实现服务器端与客户端之间双向数据传递.客户端向服务器端发送"请输出从1到1000内所有 ...

  3. 通过AIDL在两个APP之间Service通信

    一.项目介绍 [知识准备] ①Android Interface definition language(aidl,android接口定义语言),其目的实现跨进程的调用.进程是程序在os中执行的载体, ...

  4. 同一个Tomcat部署两个project之间的通信问题

    同一个tomcat下的两个project是无法通信的. 同一个tomcat中的project能互相调用吗 启动一个tomcat部署多个项目,那么每个项目算是一个线程还是进程呢? Tomcat中的pro ...

  5. 【Spring AOP】暴力打通两个切面之间的通信

    场景描述 在秒杀微服务中,笔者在需要各种校验前端传来的参数后,通过 Redis 加锁限流(切面A)并返回,最后封装订单数据推送到 RabbitMQ 消息队列(切面B)做善后工作. 问题:如何将 切面 ...

  6. vue2.0中父子组件之间的通信总结

    父组件: 子组件: 接受父组件的信息: 向父组件发送事件: (其中slot是插槽,可以将父组件中的<p>123</p>插入进来,如果父组件没有插入的内容,则显示slot内部的内 ...

  7. Delphi 两个应用程序(进程)之间的通信

    两个应用程序之间的通信实际上是两个进程之间的通信.由于本人知识有限,决定应用消息来实现.需要用到的知识: 1.RegisterWindowMessage(); //参数类型:pchar:返回值:Lon ...

  8. Python_架构、同一台电脑上两个py文件通信、两台电脑如何通信、几十台电脑如何通信、更多电脑之间的通信、库、端口号

    1.架构 C/S架构(鼻祖) C:client  客户端 S:server  服务器 早期使用的一种架构,目前的各种app使用的就是这种架构,它的表现形式就是拥有专门的app. B/S架构(隶属于C/ ...

  9. Fragment之间的通信(四)

    自定义两个fragment的布局和java类. 在mainactivity中引用布局文件 在其中的一个fragment中的控件上添加监听,获取到另一个fragment中控件的内容,展示出来完成frag ...

随机推荐

  1. Android HandlerThread 的使用及其Demo (转)

    转自http://www.cnblogs.com/hnrainll/p/3597246.html 介绍 首先我们来看看为什么我们要使用HandlerThread?在我们的应用程序当中为了实现同时完成多 ...

  2. linux grep

    grep (缩写来自Globally search a Regular Expression and Print) 是一种强大的文本搜 索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来.Uni ...

  3. EL与Velocity基本语法总结:

    El(expression language): 基本语法点: $与{}搭配使用是常态取值 . 与[]的区别,后者可以取特殊值:- .等 支持一些基本的逻辑运算: && || > ...

  4. iOS与JS交互实战篇(ObjC版)

    前言 ObjectiveC与Js交互是常见的需求,可对于新手或者所谓的高手而言,其实并不是那么简单明了.这里只介绍iOS7.0后出来的JavaScriptCore framework. 关于JavaS ...

  5. Error:Execution failed for task ':app:mergeDebugResources'. > Some file crunching failed, see logs f

    今天调试安卓程序遇到的问题Error:Execution failed for task ':app:mergeDebugResources'. > Some file crunching fa ...

  6. linux计划任务

    一.单一计划任务 安装at: # yum -y install at 启动: # /etc/init.d/atd start 查看是否运行: # ps aux | grep atd 创建计划 # at ...

  7. 前端学习 第六弹: javascript中的函数与闭包

    前端学习 第六弹:  javascript中的函数与闭包 当function里嵌套function时,内部的function可以访问外部function里的变量 function foo(x) {   ...

  8. nwjs解决页面透明化,启动时显示白屏的问题

    这些天在弄nwjs还好能访问外网,可以看到官方的文档,要不然真是欲哭无泪了,找不到相关的文档解决不了问题.主要说说怎么页面透明化的时候,出现白屏一闪问题吧.主要工具: AngularJS+node+n ...

  9. 用c#中的WebBrowser抢小米F码,抢小米手机以及自动测试实现原理

    首先是用c#中的WebBrowser控件打开登录网页,很简单,拖拽WebBrowser到Form上,然后给它的Url属性赋值.WebBrowser就会自动navigate to 这个网页. WebBr ...

  10. Eclipse中将Java项目转换成Web项目的方法

    前言: 用Eclipse开发项目的时候,把一个Web项目导入到Eclipse里会变成了一个java工程,将无法在Tomcat中进行部署运行. 方法: 1.找到.project文件,找到里面的<n ...