[ActionScript 3.0] 两个AIR之间的通信示例LocalConnection
发送方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的更多相关文章
- Android中两个Activity之间简单通信
在Android中,一个界面被称为一个activity,在两个界面之间通信,采用的是使用一个中间传话者(即Intent类)的模式,而不是直接通信. 下面演示如何实现两个activity之间的通信. 信 ...
- 基于WSAAsyncSelect模型的两台计算机之间的通信
任务目标 编写Win32程序模拟实现基于WSAAsyncSelect模型的两台计算机之间的通信,要求编程实现服务器端与客户端之间双向数据传递.客户端向服务器端发送"请输出从1到1000内所有 ...
- 通过AIDL在两个APP之间Service通信
一.项目介绍 [知识准备] ①Android Interface definition language(aidl,android接口定义语言),其目的实现跨进程的调用.进程是程序在os中执行的载体, ...
- 同一个Tomcat部署两个project之间的通信问题
同一个tomcat下的两个project是无法通信的. 同一个tomcat中的project能互相调用吗 启动一个tomcat部署多个项目,那么每个项目算是一个线程还是进程呢? Tomcat中的pro ...
- 【Spring AOP】暴力打通两个切面之间的通信
场景描述 在秒杀微服务中,笔者在需要各种校验前端传来的参数后,通过 Redis 加锁限流(切面A)并返回,最后封装订单数据推送到 RabbitMQ 消息队列(切面B)做善后工作. 问题:如何将 切面 ...
- vue2.0中父子组件之间的通信总结
父组件: 子组件: 接受父组件的信息: 向父组件发送事件: (其中slot是插槽,可以将父组件中的<p>123</p>插入进来,如果父组件没有插入的内容,则显示slot内部的内 ...
- Delphi 两个应用程序(进程)之间的通信
两个应用程序之间的通信实际上是两个进程之间的通信.由于本人知识有限,决定应用消息来实现.需要用到的知识: 1.RegisterWindowMessage(); //参数类型:pchar:返回值:Lon ...
- Python_架构、同一台电脑上两个py文件通信、两台电脑如何通信、几十台电脑如何通信、更多电脑之间的通信、库、端口号
1.架构 C/S架构(鼻祖) C:client 客户端 S:server 服务器 早期使用的一种架构,目前的各种app使用的就是这种架构,它的表现形式就是拥有专门的app. B/S架构(隶属于C/ ...
- Fragment之间的通信(四)
自定义两个fragment的布局和java类. 在mainactivity中引用布局文件 在其中的一个fragment中的控件上添加监听,获取到另一个fragment中控件的内容,展示出来完成frag ...
随机推荐
- 前端二:CSS
CSS: 一:介绍:学名层叠样式表(Cading Style Sheets)是一种用来表现HTML或者XML等文件的样式的计算机语言.让HTML和XML看起来更加美观. 语法:<style> ...
- Centos 7防火墙firewalld开放80端口(转)
开启80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent 出现success表明添加成功 命令含义: --zone #作用域 -- ...
- Gradle简介和安装
一.Gradle介绍 Gradle是一个基于JVM的构建工具,它提供了:像Ant一样,通用灵活的构建工具,可以切换的,基于约定的构建框架,强大的多工程构建支持,基于Apache Ivy的强大的依赖管理 ...
- IONIC 开发的Android应用程序签名(或重新签名)详解
完全通过DOS命令来完成apk签名 给apk签名一共要用到3个工具,或者说3个命令,分别是:keytool.jarsigner和zipalign,下面是对这3个工具的简单介绍: ...
- PP 创建BOM
转自 http://blog.csdn.net/u012369651/article/details/19190939 一.最终结果预览. 二.创建过程. 使用到的事务码 CS01 创建BOM CS0 ...
- 求第K大数
1.排序找第K个数 2.快速排序分块 时间复杂度 2呢
- Baidu set to lose leading role in digital advertising _china daily
advertising: n,广告 Online search giant Baidu Inc is set to loset its top spot in the nation's booming ...
- MAC的终端命令
今天小研究了一下MAC的终端命令,主要为了方便调试程序用,XCODE用不来啊... 在这里记下..防止丢失 pwd 当前工作目录 cd(不加参数) 进root cd(folder) 进入文件夹 cd ...
- RPC与hadoop
rlgdj的这样的话,真正的实现类在Server端,客户端调用方法的时候,只能得到得到从Server端的返回值.看来接口中的抽象方法必须要有返回值啊.ps.右下角的Client端的main()中rpc ...
- js获取ip地址
方法三(所有的平台及浏览器):使用的搜狐接口 <script src="http://pv.sohu.com/cityjson?ie=utf-8"></scrip ...