# Parent SWF controlling Child SWF variables

**URL:** https://forum.kirupa.com/t/parent-swf-controlling-child-swf-variables/279186
**Category:** flash
**Created:** [January 11, 2009, 12:58am UTC](https://forum.kirupa.com/t/parent-swf-controlling-child-swf-variables/279186 "2009-01-11T00:58:11Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Paradise\_Wolf](https://avatars.discourse-cdn.com/v4/letter/p/85e7bf/32.png) [@Paradise\_Wolf](https://forum.kirupa.com/u/Paradise_Wolf)
#### Post date: [January 11, 2009, 12:58am UTC](https://forum.kirupa.com/t/parent-swf-controlling-child-swf-variables/279186/1 "2009-01-11T00:58:11Z")

</div>

1. 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 ?

2. Why this code needs to use the \*\*ExternalInterface \*\*class if the Child SWF gets loaded and becomes incorporated in the Parent SWF ?

3. 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]
