# Loader occurring multiple times

**URL:** <https://forum.kirupa.com/t/loader-occurring-multiple-times/237418>\
**Category:** flash\
**Created:** [August 30, 2007, 6:16am UTC](https://forum.kirupa.com/t/loader-occurring-multiple-times/237418 "2007-08-30T06:16:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tsukiyomi](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Tsukiyomi](https://forum.kirupa.com/u/Tsukiyomi)\
**Post date:** [August 30, 2007, 6:16am UTC](https://forum.kirupa.com/t/loader-occurring-multiple-times/237418/1 "2007-08-30T06:16:35Z")

</div>

```auto
one_btn.addEventListener(MouseEvent.MOUSE_UP, buttonAction);
two_btn.addEventListener(MouseEvent.MOUSE_UP, buttonAction);
three_btn.addEventListener(MouseEvent.MOUSE_UP, buttonAction);
four_btn.addEventListener(MouseEvent.MOUSE_UP, buttonAction);
var container_mc:MovieClip = new MovieClip();
container_mc.x = 0;
container_mc.y = 0;

addChild(container_mc);

MovieClip(loadbar).alpha = 0;
MovieClip(stroke_mc).alpha = 0;

function buttonAction(e:MouseEvent):void {
    MovieClip(loadbar).alpha = 100;
    MovieClip(stroke_mc).alpha = 100;
    var t:String = String(e.target.name);
    var a:Array = String(t).split("_");
    var the_url:URLRequest = new URLRequest();
    the_url.url = "images/" + a[0] + ".jpg";
    
    var the_loader:Loader = new Loader();
    the_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
    the_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
    while (container_mc.numChildren > 0) {
        container_mc.removeChildAt(0);
    }
    the_loader.load(the_url);
}
function onLoaderProgress(e:Event):void {
    MovieClip(loadbar).scaleX = e.target.bytesLoaded / e.target.bytesTotal
}
function onLoaderComplete(e:Event):void {
    container_mc.addChild(e.target.content);
    e.target.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
    e.target.addEventListener(Event.COMPLETE, onLoaderComplete);
    MovieClip(loadbar).alpha = 0;
    MovieClip(stroke_mc).alpha = 0;
}

```

Whenever I load something, if I click a second button while one of the others is in the process of loading the previous one continues to load. So if I clicked button 1 then clicked button 2 while button 1’s content was still loading, the content for button 1 still loads and when its finished it shows.

How do I remedy this? In AS2 a container would only hold one external clip at a time, but that is no longer the case and I’m kind of at a loss here.

Thanks.
