[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 ...
随机推荐
- 火车头wordpress免费万能发布模块和接口
火车头wordpress免费万能发布模块和接口实测可以用 http://www.ggfenxiang8.com/?p=263
- cosine similarity
Cosine similarity is a measure of similarity between two non zero vectors of an inner product space ...
- 关于 escape、encodeURI、encodeURIComponent
参考资料:http://hi.baidu.com/flondon/item/983b3af35b83fa13ce9f3291 http://www.w3school.com.cn/js/jsref ...
- Spring 的 NamedParameterJdbcTemplate(转)
NamedParameterJdbcTemplate类是基于JdbcTemplate类,并对它进行了封装从而支持命名参数特性. NamedParameterJdbcTemplate主要提供以下三类方法 ...
- Tomcat口令猜解工具【Python脚本】
Tomcat 服务器网页部署,登录需用户名/密码,编写了一个简单的Python脚本来测试一些简单的弱口令. 测试环境:Tomcat版本 7.0 登录界面采用basic认证,Base 64加密一下,模拟 ...
- 安装ftp 服务器
安装ftp 服务器 #yum install vsftp 安装ftp 客户端 重启ftp服务器 sudo /etc/init.d/vsftpd restart /start /stop 进行ARM 和 ...
- VMvare克隆复制多个操作系统
目的:完成linux的双机和集群实验 2016-12-06 在网上查找了一些资料现整理如下,以供之后查看和帮助他人. 注意事项: 1.关闭源虚拟机的电源: 操作很简单 选择完整创建 输入源克隆机的用户 ...
- 简谈ashx
是一般处理程序, 是asp.net web 组件的一种,ashx是其扩展名. 实现IHttpHandler接口,接收并处理http请求.这个接口有一个IsReusable成员,一个待实现的方法Proc ...
- Atom安装activate-power-mode插件(震动炫酷)
1.下载安装Atom,地址:https://atom.io/ 2.下载安装activate-power-mode插件,地址:https://github.com/JoelBesada/activate ...
- NewQuant的设计(一)——整体的领域设计
NewQuant的设计思路——整体的领域分析 “领域驱动设计(DDD)”是著名软件工程建模专家Eric Evans提出的一个重要概念,是“面向对象分析设计(OOAD)”的深化.当业务逻辑变得复杂,系统 ...