-
The code below works but the browser sends an annoying alert message “Received Parent Message” and you are obliged to click OK before the program can run. How can it be fixed ?
-
Why this code needs to use the **ExternalInterface **class if the Child SWF gets loaded and becomes incorporated in the Parent SWF ?
-
Is there a simpler and more straightforward way for a Parent SWF to communicate with a Child SWF ?
[COLOR=“Blue”]package
{
import flash.external.ExternalInterface;
import flash.display.Sprite;
import flash.text.*;
public class ChildMovie extends Sprite
{
public function ChildMovie():void
{
//…
}
public function alert(msg:String):void
{
**ExternalInterface**.call('alert', msg);
txt.text = msg;
}
}
}
package
{
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.LoaderInfo;
import flash.display.Sprite;
public class ParentMovie extends Sprite
{
public function ParentMovie():void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest('ChildMovie.swf'));
}
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');
}
}
}
[/COLOR]