# Display object contentLoader issue

**URL:** <https://forum.kirupa.com/t/display-object-contentloader-issue/313252>\
**Category:** Uncategorized\
**Created:** [August 25, 2010, 2:32am UTC](https://forum.kirupa.com/t/display-object-contentloader-issue/313252 "2010-08-25T02:32:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrzdzn](https://avatars.discourse-cdn.com/v4/letter/w/73ab20/32.png) [@wrzdzn](https://forum.kirupa.com/u/wrzdzn)\
**Post date:** [August 25, 2010, 2:32am UTC](https://forum.kirupa.com/t/display-object-contentloader-issue/313252/1 "2010-08-25T02:32:55Z")

</div>

Hello can anyone please help me with this removeChild / display object issue. My code below loads my preloader dynamically before an image is loaded into the file and when it finishes I want to remove my preloader by the removeChild(); method. Whenever I try to add removeChild(); in my code my file either does not work or I get an error #2025 must be a child of the caller. Where would my code go for the removeChild to work and not have a conflict. I know I probably need some removeEventListeners as well at the bottom: **My .fla file is attached it works but I just need to remove the preloader in my code after it loads my image**.  
Any help would be great. Thanks

\*\*my code: I need to remove my preloader when it reaches 100%  
and my image is loaded  
\*\*var myRequest:URLRequest = new URLRequest(“baer.jpg”);  
var myloader:Loader = new Loader();  
myloader.load(myRequest);  
c\_btn.addEventListener(MouseEvent.MOUSE\_UP, loadA);  
var preLoad:preloader=new preloader();

function loadA(event:MouseEvent):void  
{  
addChild(myloader);  
myloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);  
}

function progressHandler(myeventProgressEvent):void  
{  
addChild(preLoad);  
preLoad.x = 450;  
preLoad.y = 300;  
var myprogress:Number = myevent.target.bytesLoaded / myevent.target.bytesTotal;  
preLoad.bar\_mc.scaleX = myprogress;  
preLoad.myTextField\_txt.text = Math.round(myprogress \* 100) + “%”;

}  
\*\* maybe something like this below but I cannot get it to work\*\*

root.loaderInfo.addEventListener(Event.COMPLETE, finished);  
function finished(myevent:Event):void {  
//Remove the event listeners to make sure they aren’t fired twice  
root.loaderInfo.removeEventListener(Event.COMPLETE, finished);  
root.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler);  
removeChild(preLoad);  
}
