swf文件间通信

parent:
var loader:Loader = new Loader();
var shared:EventDispatcher = loader.contentLoaderInfo.sharedEvents;
shared.addEventListener("fromChild", fromChild);
var url:String = "E:\\Work\\TONE-RICH\\workcvsroot\\iWo\\小额支付.swf";
loader.load(new URLRequest(url));
function fromChild(event:TextEvent):void 
{
trace(event.text); // Good day
var replyMessage:TextEvent = new TextEvent("fromParent");
replyMessage.text = "Same to you";
shared.dispatchEvent(replyMessage);
}
 
 
child:
var shared:EventDispatcher = loaderInfo.sharedEvents;
shared.addEventListener("fromParent", fromParent);
var firstMessage:TextEvent = new TextEvent("fromChild");
firstMessage.text = "Good Day";
shared.dispatchEvent(firstMessage);
function fromParent(event:TextEvent):void 
{
     trace(event.text); // Same to you
}
 
 
parent调用child获得返回值:
var loader:Loader = new Loader();
var shared:EventDispatcher = loader.contentLoaderInfo.sharedEvents;
shared.addEventListener("fromChild", fromChild);
var url:String = "E:\\Work\\TONE-RICH\\workcvsroot\\iWo\\小额支付.swf";
loader.load(new URLRequest(url));
function fromChild(event:TextEvent):void 
{
trace(event.text); // 获得返回值
}
 
child 返回数据给调用者:
var shared:EventDispatcher = loaderInfo.sharedEvents;
var firstMessage:TextEvent = new TextEvent("fromChild");
firstMessage.text = "Hello Parent";
shared.dispatchEvent(firstMessage);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值