Tuesday, September 11, 2007
as3: accessing loaded swf stuff
Tuesday, September 11, 2007
In my main AS3 document class, I am loading a SWF into a MovieClip, and then later would like to access vars, methods, etc. within it from my main class. As a test in my SWF that gets loaded in I have a simple variable: var foo:String = "iam"; -- now to access that I found this out (works):
Update:
private function loadViewElements():voidThis works just fine, but wondering if I should set up private variables to hold those objects for easy access later on in my document class above the constructor and in the complete event, like so:
{
var module1Loader:Loader = new Loader();
module1Loader.contentLoaderInfo.addEventListener(
Event.COMPLETE, completeEvent );
module1Loader.contentLoaderInfo.addEventListener(
IOErrorEvent.IO_ERROR, ioError );
// Create and load the Views
NUMBERPAD = new MovieClip();
addChild( NUMBERPAD );
NUMBERPAD.addChild( module1Loader );
var moduleURL:URLRequest = new URLRequest( "views/view.swf" );
module1Loader.load( moduleURL );
}
private function completeEvent( event:Event ):void
{
var foo:Object = NUMBERPAD.getChildAt(0);
trace( foo.numChildren ); // 1
trace( foo.getChildAt(0).iam ); // iam
}
private var NUMBERPAD_CONTENTS:Object;Just to make things clearer and much easier to access. Or is there a much more simple way of approaching this?
// within compete event below:
NUMBERPAD_CONTENTS = foo.getChildAt(0);
trace( NUMBERPAD_CONTENTS.iam ); // iam
Update:
trace( event.target.content.iam );Well, that out to do it ;) BUT, how can I get the name of the mc that the loader is inside... so I can use a generic loader and assign vars to certain things?
Comments:
There are currently 3 Comments:
-
Muzak said...“To get to the loaded content, use LoaderInfo.content (as you already figured out).
To get to the movieclip that holds the Loader, use the class member, NUMBERPAD.”


