解决两个swf间通讯的问题,
例子:
A.swf源码:
package {
import flash.display.MovieClip;
import flash.external.ExternalInterface;
import flash.system.Security;
import flash.net.LocalConnection;
import flash.events.Event;
import flash.events.StatusEvent;
import flash.display.StageQuality;
public class a extends MovieClip {
var con:LocalConnection;
var id:Number;
public function a() {
stage.quality=StageQuality.MEDIUM;
Security.allowDomain('*');
init();
}
function init():void {
con = new LocalConnection();
con.addEventListener(StatusEvent.STATUS, onStatus);
if (loaderInfo.parameters["f"]==null) {
id=10;
} else {
id=loaderInfo.parameters["f"];
}
this.addEventListener(Event.ENTER_FRAME,onEventFrameHandler);
}
function onEventFrameHandler(evt:Event):void {
txt.text=currentFrame.toString()+ " = lc_name"+id;
if ((currentFrame==1) || (currentFrame==51) || (currentFrame==101) || (currentFrame==151) || (currentFrame==201)) {
con.send("lc_name"+id, "lcHandler",currentFrame.toString());
}
}
function onStatus(event:StatusEvent):void {
switch (event.level) {
case "status" :
//trace("LocalConnection.send() succeeded");
break;
case "error" :
//trace("LocalConnection.send() failed");
break;
}
}
}
}
B.swf源码:
package {
import flash.external.ExternalInterface;
import flash.system.Security;
import flash.net.LocalConnection;
import flash.events.Event;
import flash.events.StatusEvent;
import flash.display.MovieClip;
import flash.display.StageQuality;
public class b extends MovieClip {
var id:Number;
private var con:LocalConnection;
public function b() {
//stop();
stage.quality=StageQuality.MEDIUM;
Security.allowDomain('*');
init();
this.addEventListener(Event.ENTER_FRAME,onEventFrameHandler);
}
function init():void {
con = new LocalConnection();
con.client=this;
if (loaderInfo.parameters["f"]==null) {
id=10;
} else {
id=loaderInfo.parameters["f"];
}
try {
con.connect("lc_name"+id);
} catch (error:ArgumentError) {
txt.text="Can't connect...the connection name is already being used by another SWF";
}
}
public function lcHandler(val:Number):void {
this.gotoAndPlay(val+1);
//txt.text='- : '+val;
}
function onEventFrameHandler(evt:Event):void {
txt.text=currentFrame.toString()+' = '+ "lc_name"+id;
}
}
}
注:
为了避免在多个浏览器上面查看页面效果时,两个swf连接之间的干扰,此例中的:loaderInfo.parameters["f"],是从js那里取了个随机数,来对不同浏览器页面设置不同的连接名,避免同名连接干扰...
分享到:
相关推荐
Flex中SWF和其他SWF文件之间的通信原理。该案例中TestLocalConnection为主SWF文件加载了TestLocalConnectionReceiver.SWF,两者之间是在同一个域下的...其他技术细节参见Flex_API中的LocalConnection章节。本机测试通过
多个swf的通讯,使用 LocalConnection 类可以创建一个 LocalConnection 对象,该对象可在一个 SWF 文件中或多个 SWF 文件间,调用另一个 LocalConnection 对象中的方法。
一个关于flex 中flash文件通信的说明。actionscript3.0
一个localConnection的例子
flash localconnection问题源文件
NULL 博文链接:https://globle.iteye.com/blog/748144
LocalConnection的问题
as3 加载 as2的通讯,flex调用 as2的
##使用说明###简介通过flash进行同一浏览器跨页面,跨内核的通讯。###外链形式[removed][removed][removed] localConnect.init();[removed]###模块加载形式[removed] require(['/module/localConnect/1.0.0/...
第30章AdobeAIR应用——本地播放器 644 30.1分析与设计 644 30.1.1功能分析 644 30.1.2界面设计 645 30.1.3模块设置 647 30.2建立项目 649 30.3创建新组件 650 30.3.1创建滚动容器组件 650 30.3.2创建复选框组件 653...
2)本插件是基于同一台电脑上的FLASH之间能进行LocalConnection以及FLASH与JS能相互调用的原理而设计,将客户端不同域页面间Javascript相互调用转化为了FLASH之间的"本地命令发送". 3)本插件在不同域页面间Javascript...
利用iframe和location.hash,数据直接暴露在了url中,数据容量和类型都有限 3.Flash LocalConnection, 对象可在一个 SWF 文件中或多个 SWF 文件间进行通信, 只要 在同一客户端就行,跨应用程序, 可以跨域。...
Chapter 4 - Using External API and LocalConnection Chapter 5 - Working with XML Chapter 6 - Overview of LiveCycle Data Services and BlazeDS Chapter 7 - Flex Data Access Methods Chapter 8 - ...
LocalConnection and DataProvider 使用方法範例
从导入到安全域的SWF文件加载嵌入内容 使用旧内容 设置LocalConnection权限 控制外出URL访问 共享对象 摄像头、麦克风、剪贴板、鼠标和键盘访问 AIR安全性 第章:如何使用ActionScript示例 示例类型 在...
asLocalConnect是在ActionScript 2 / ActionScript 3中进行LocalConnection的更好方法。功能:心跳,同步,onLoad / onUnload事件处理程序,广播,LocalConenct通道和其他不错的功能。
在之前一篇文章里尝试了跨浏览器的数据共享,最后提到使用LocalConnection还可以实现跨浏览器消息交互的可行性。 花了两个晚上简略的研究了下,LocalConnection的单向通信非常的简单,不过要实现多个终端交互,...
About this manual 13 ...Setting LocalConnection permissions.790 Controlling access to scripts in a host web page..790 Shared objects...792 Camera, microphone, clipboard, mouse, and keyboard access.794
hasMP3 System.capabilities.hasMP3 hasPrinting System.capabilities.hasPrinting hasScreenBroadcast System.capabilities.hasScreenBroadcast hasScreenPlayback System.capabilities.hasScreenPlayback ...