Ultrashock Forums > Flash > ActionScript
AS3 - acccessing vars from parent when loading external swf
Member Blogs
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
AS3 - acccessing vars from parent when loading external swf
Old 2008-07-08

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?
postbit arrow 1 comment | 538 views postbit arrow Reply: with Quote   
simpelito
Registered User
simpelito is offline
seperator
Posts: 6
2008-06-04
simpelito lives in Sweden
seperator

Ultrashock Member Comments:
Nutrox's Avatar Nutrox Nutrox is offline Nutrox lives in United Kingdom 1 Blog Entries 13 Creative Assets 2008-07-08 #2 Old  
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...
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...
Code:
package
{
	import flash.display.Sprite;

	public class ExampleB extends Sprite
	{
		public function ExampleB()
		{}

		public function init( param:String ):void
		{
			trace( param ); // hello
		}
	}
}
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: