Hi all!
I’m missing something crucial here I think…
I’m making a preloader/container swf for a site we’re producing. My idea is to have a generic preloader swf that gets a number of settings from an xml file, saves them all in a Dictionary and then loads an external swf that is used to display the content. A pretty common approach I think, or isn’t it?
The problem though is how do I access variables created in my preloader swf from the externally loaded swf? In AS2 I could just get the vars by starting with _root.whatever but that doesn’t seem to be possible in AS3, right?
It is better to call some kind of init method in the loaded SWF file, you can pass the data easily and directly to the loaded SWF that way.
Preloader (parent) code…
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public class ExampleA extends Sprite
{
private var loader:Loader = new Loader();
public function ExampleA()
{
loader.contentLoaderInfo.addEventListener( Event.INIT, onLoaderInit );
loader.load( new URLRequest( "ExampleB.swf" ) );
}
private function onLoaderInit( e:Event ):void
{
Object( loader.content ).init( "hello" );
}
}
}
Main (child) code…
package
{
import flash.display.Sprite;
public class ExampleB extends Sprite
{
public function ExampleB()
{}
public function init( param:String ):void
{
trace( param ); // hello
}
}
}
- 08 July 2008 01:06 PM
-
Nutrox,
Bless you. I’ve been searching for hours for a solution to this problem. This gets the job done. Thank you!
I try to remind myself that smart people seem to think AS3 is a step in the right direction, but God help me… it just isn’t. I defy anyone to explain why all of that init code if more efficient or logical than in AS2 where a child clip would simply say:
trace(_parent.variableInPreloader)
*head in hands*
- 13 January 2009 02:07 AM
-
- Log in or join for free to make a comment.


