Access flashvars from a loaded swf (1)
February 12th, 2009 by terrypaton, under Library.
To access the flashVars from a swf loaded into another swf use:
var test:String = String(stage.loaderInfo.parameters.myFlashVars)
February 12th, 2009 by terrypaton, under Library.
To access the flashVars from a swf loaded into another swf use:
var test:String = String(stage.loaderInfo.parameters.myFlashVars)
An import point: This will not work unless the loaded swf has already been added to the display list.
Consider this code in your main swf, where code in frame one of loaded.swf tries to access a FlashVar:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest(“loaded.swf”));
function completeHandler(event:Event):void
{
addChild(loader); // here’s where your swf gets added to the display list
// Handle other init tasks
}
This will not work, because the code in frame one of loaded.swf will have already executed when completeHandler() is called. To get this to work, you have to move the addChild(loader) line:
var loader:Loader = new Loader();
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest(“loaded.swf”));
function completeHandler(event:Event):void
{
// Handle other init tasks
}