# Loader Object Reference from MovieClip

**URL:** <https://forum.kirupa.com/t/loader-object-reference-from-movieclip/278252>\
**Category:** Uncategorized\
**Created:** [December 24, 2008, 6:40pm UTC](https://forum.kirupa.com/t/loader-object-reference-from-movieclip/278252 "2008-12-24T18:40:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xFlashStudentx](https://avatars.discourse-cdn.com/v4/letter/x/57b2e6/32.png) [@xFlashStudentx](https://forum.kirupa.com/u/xFlashStudentx)\
**Post date:** [December 24, 2008, 6:40pm UTC](https://forum.kirupa.com/t/loader-object-reference-from-movieclip/278252/1 "2008-12-24T18:40:18Z")

</div>

Good afternoon coders. I’m trying to reference a loader Object on the maintime line from within a MovieClip. More clearly, when I press one of my buttons (myCars or myVideos) I need my transition movieclip named container to play. Once the movieclip reaches a particular frame, I need the code in that frame to run.

**First, here’s the code on the main timeline:**

import flash.display.\*;

var my\_loader:Loader = new Loader();  
addChild(my\_loader);

var container:blue=new blue();  
container.name = “myContainer”;  
container.x=10.0;  
container.y=74.0;  
this.addChild(container);

var lastLoaded:String;

myVideos.addEventListener(MouseEvent.MOUSE\_DOWN, loadTheBaby);  
myCars.addEventListener(MouseEvent.MOUSE\_DOWN, loadTheCars);

function loadTheBaby (e:MouseEvent):void{  
if(e.currentTarget.name !=lastLoaded){  
lastLoaded=e.currentTarget.name;  
container.gotoAndPlay(“motivate”);

}  
}

function loadTheCars (e:MouseEvent):void{  
if(e.currentTarget.name !=lastLoaded){  
lastLoaded=e.currentTarget.name;  
container.gotoAndPlay(“motivate”);

}  
}

\*\*Now, here’s the code I need to run when the movieclip named container reaches a certain frame:  
\*\*  
stop();

[//lastLoaded=e.currentTarget.name](https://lastLoaded=e.currentTarget.name);  
my\_loader.load(new URLRequest(lastLoaded+".swf"));  
my\_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);  
my\_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);

function loop(e:ProgressEvent):void  
{  
var perc:Number = e.bytesLoaded / e.bytesTotal;  
percent.text = Math.ceil(perc\*100).toString();  
}

function done(e:Event):void  
{  
removeChildAt(0);  
percent = null;  
addChild(my\_loader);  
gotoAndPlay(“closeup”);  
}

**Here are the error messages:**

1120: Access of undefined property my\_loader.  
1120: Access of undefined property lastLoaded.

the variable lastLoaded is on the main timeline, and the loader Object my\_loader is also on the main timeline. So, I believe I need to reference the loader Object and the lastLoaded variable on the main timeline from within a movieclip. I tried root.my\_loader; I tried parent.my\_loader to no avail. I even tried to put the loader object and the lastLoaded var in the movieclip and ran into a laundry list of errors. Is there a new way to access objects and variables on the main timeline from within a movieclip? Please steer me in the right diirection. Thanks for reading.

xFLASHSTUDENTx
