# Can't remove all loaded children in a gallery because can't close() a loader!

**URL:** https://forum.kirupa.com/t/cant-remove-all-loaded-children-in-a-gallery-because-cant-close-a-loader/323047
**Category:** flash
**Created:** [June 15, 2011, 7:43am UTC](https://forum.kirupa.com/t/cant-remove-all-loaded-children-in-a-gallery-because-cant-close-a-loader/323047 "2011-06-15T07:43:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![nlalli87](https://avatars.discourse-cdn.com/v4/letter/n/c89c15/32.png) [@nlalli87](https://forum.kirupa.com/u/nlalli87)
#### Post date: [June 15, 2011, 7:43am UTC](https://forum.kirupa.com/t/cant-remove-all-loaded-children-in-a-gallery-because-cant-close-a-loader/323047/1 "2011-06-15T07:43:31Z")

</div>

0 down vote [favorite](http://stackoverflow.com/questions/6352486/cant-remove-all-loaded-children-in-a-gallery-because-cant-close-a-loader#)  
This is the code i used in a gallery that loads images sequentally. My problems comes in when you have to open a different image album and have to eliminate all the previously loaded children in the movieclip. The problem is that sometimes the user leaves the album page before ALL the pics laod so when they click on a new album to open it a new image is placed somewhere else cause the loader has already been launched. I’ve tryd to close() the loader but it doesn’t seem to work. I’d appreciate it inmensly if you can give me a hand. Thanks in advanced. Here you can see the working site [www.barbarabritvin.com](http://www.barbarabritvin.com) (to see what im talking about you have to click on an album, leave before all the pictures load and open up another one. Cheers from Argentina!

getImage(dataList[0].file)

function getImage(href:String):void {

var loader:Loader = new Loader();  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageReady);  
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);  
loader.x=xCounter  
loader.load(new URLRequest(href));

}

function imageReady(e:Event):void {  
var bitmap:Bitmap=e.target.content;  
if (bitmap!=null) {  
bitmap.smoothing=true;  
}

displayLarge2.thumb\_loader.thumbHolderInside.addChildAt(e.target.loader,0)  
yaCargo=true

trace(“NUMCHILDREN”+displayLarge2.thumb\_loader.thumbHolderInside.numChildren)

collection.push(e.target.content);  
xCounter=xCounter+e.target.loader.width+3  
imagecounter++;  
if(imagecounter \< dataList.length() && loadingPics==true) {  
getImage(dataList[imagecounter].file);  
}

}

function clearThumbs():void  
{  
while(displayLarge2.thumb\_loader.thumbHolderInside.numChildren \> 0)  
{  
//Remove the first child until there are none.  
displayLarge2.thumb\_loader.thumbHolderInside.removeChildAt(0);  
}  
}

displayLarge2.close.addEventListener(MouseEvent.CLICK, closeAlbum)

function closeAlbum(e:MouseEvent):void{  
displayLarge2.thumb\_loader.thumbHolderInside.enabled=false  
loadingPics=false

```
        while(displayLarge2.thumb_loader.thumbHolderInside.numChildren&gt;0) 
{ 
      displayLarge2.thumb_loader.thumbHolderInside.removeChildAt(0)
} 

    trace("NUMCHILDREN"+displayLarge2.thumb_loader.thumbHolderInside.numChildren)

```

imagecounter=0  
xCounter=0

displayLarge2.enabled=false  
displayLarge2.mouseChildren=false

var scrollerTween=TweenManager.create(displayLarge2,“alpha”,Regular.easeIn,1,0,0.5,true);  
scrollerTween.addEventListener(TweenEvent.MOTION\_FINISH, doNextTween)  
function doNextTween(e:TweenEvent):void{

```
sectionThumbs.enabled=true
sectionThumbs.mouseChildren=true
displayLarge2.visible=false

var thumbsTween=TweenManager.create(sectionThumbs,"alpha",Regular.easeIn,0,1,0.5,true);
scrollerTween.removeEventListener(TweenEvent.MOTION_FINISH, doNextTween)

```

}

}
