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);