Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

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):
private function loadViewElements():void
{
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
}
This 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:
private var NUMBERPAD_CONTENTS:Object;
// within compete event below:
NUMBERPAD_CONTENTS = foo.getChildAt(0);
trace( NUMBERPAD_CONTENTS.iam ); // iam
Just to make things clearer and much easier to access. Or is there a much more simple way of approaching this?

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?
 
 Return to the main page
Comments:

There are currently 3 Comments:

Blogger 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.”
 
Blogger Tom said...
September 12, 2007 3:16 PM
“I know this is probably very simple, but how do I call stop(); or play(); on a loaded SWF? (Working in the Flash CS3 IDE--no Flex)

I've tried this.mcLoader_mc.content.stop();, but get compiler errors.

Thanks!
Tom”
 
Blogger e.dolecki said...
September 12, 2007 3:35 PM
“Tom,
Your code doesn't look correct. It should be something more like: event.target.content.stop(); within the Loader event.”
 
 Leave a comment