[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 ...
随机推荐
- mac下获取应用签名
查看md5和SHA1: universalbroker.jks为签名文件 keytool -list -v -keystore universalbroker.jks 微信分享和登录平台需要去掉冒号的 ...
- 腾讯优测优分享 | Android适配中的一些特殊情况小结
腾讯优测是专业的自动化测试平台,提供全面兼容适配测试,远程真机租用等多维度的测试服务! 作为一名"艰苦卓绝"的软件工程师,我在开发路上经常被各种奇葩情况虐的体无完肤...今天就想与 ...
- LintCode StrStr
1. 讨论目标字符串若为空, 则返回-1: 资源字符串若为空, 则返回-1. 2.讨论目标字符串个数为零, 则返回0: 资源字符串个数为零, 则返回-1. 3. 插入旗帜来使第二循环的结束为有条件地返 ...
- bootstrap-15
缩略图:缩略图在网站中最常用的地方就是产品列表页面,一行显示几张图片,有的在图片底下(左侧或者右侧)带有标题.描述信息.Bootstrap框架将这一部独立成一个模块组件,并通过thumbnail样式配 ...
- 【Cocos2d-x 3.x】 场景切换生命周期、背景音乐播放和场景切换原理与源码分析
大部分游戏里有很多个场景,场景之间需要切换,有时候切换的时候会进行背景音乐的播放和停止,因此对这块内容进行了总结. 场景切换生命周期 场景切换用到的函数: bool Setting::init() { ...
- HDU 1016Prime Ring Problem
http://acm.hdu.edu.cn/showproblem.php?pid=1016 题意:输入一个数,给出符合要求的素数环. 经典的dfs遍历. #include<iostream&g ...
- ES6笔记一
遍历数组: 1:传统的 for (var index = 0; index < myArray.length; index++) { console.log(myArray[index]);} ...
- 【jQuery plug-in】DataTables
1. DOM Position dataTableOption.dom = '<"top"<"pull-left"l><"pu ...
- Makefile简易教程
本文部分内容引用: 中文维基百科. 一个简单的Makefile教程. Makefile简介 在软件开发中,make通常被视为一种软件构建工具.该工具主要经由读取一种名为"makefile&q ...
- 记一次ifconfig命令
由于Windows 10的强制更新,原来的Virtual box Host-Only驱动莫名奇妙的不见了,于是上网找各种解决方案: 1.重新生成虚拟网卡适配器:执行 VBoxManage.exe ho ...