views:

2509

answers:

3

I have a swf (child.swf) that I wish to load into another (parent.swf). I wish to pass a parameter to child.swf through the loader I am using. Note that I am not trying to pass FlashVars that parent.swf already has, but rather I am trying to simply load a swf through another swf with custom arguments.

Any ideas?

+4  A: 

In the child swf, write a function (init in the code below) to receive any params. When the Loader signals Event.COMPLETE, call the function from parent.swf as follows:

var request:URLRequest = new URLRequest("child.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);
loader.load(request);

function loadHandler(event:Event):void
{
   var childSwf:Object = event.target.content;
   childSwf.init( PARAMS );
}
spender
worked perfectly. Thanks!
Jeff Winkworth
A: 

Works well, but now can't seem to get the recieved PARAMS var into a global variable to manipulate/test -

public function init(PARAMS){

  var thisPARAMS:String = PARAMS
  thisplayerCall=thisPARAMS;
  trace("thisplayerCall:"+thisplayerCall);//outputs PARENT variable

 }

//MAIN CONSTRUCTOR public function final_trial():void { trace("thisplayerCall:"+thisplayerCall);//outputs null

 }

Am I missing something really obvious here??

if final_trial() is the child.swf's constructor, it would be called before init() was. That would be why you see null.
Jeff Winkworth
A: 

I think you would need a public method on your child swf called "init" to accept the vars