For instance, in the below code a parent can control the SWF child’s function “alert ()”.
But how a SWF child can control the parent’s function “ReceivingChildMsg()” ?
( Note: I am using Actionscript 3 )
public class ChildSWF extends Sprite
{
private var t:TextField;
public function ChildSWF():void
{
t = new TextField( );
t.text = "No Message from the Parent";
addChild( t );
//~~~~~~~~~~
Button.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);
}
public function alert(msg:String):void
{
t.text = msg;
}
protected function clickHandler(event:MouseEvent):void
{
ReceivingChildMsg (‘Received Child Message’);
}
########
public class ParentSWF extends Sprite
{
private var loader:Loader;
public function ParentSWF():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest('ChildSWF.swf'));
//~~~~~~~~~~~
tc = new TextField( );
tc.text = "No Message from the Child";
addChild( tc );
}
private function onLoadComplete(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
addChild(e.target.content);
var swf:Object = loaderInfo.content;
swf.x = 75;
swf.y = 50;
swf.alert('Received Parent Message');
}
public function ReceivingChildMsg ( var childsMsg:String):void
{
tc.text = childsMsg;
}
}