# Problems with loaded external jpgs

**URL:** <https://forum.kirupa.com/t/problems-with-loaded-external-jpgs/280060>\
**Category:** Uncategorized\
**Created:** [January 22, 2009, 7:27am UTC](https://forum.kirupa.com/t/problems-with-loaded-external-jpgs/280060 "2009-01-22T07:27:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigashby](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@craigashby](https://forum.kirupa.com/u/craigashby)\
**Post date:** [January 22, 2009, 7:27am UTC](https://forum.kirupa.com/t/problems-with-loaded-external-jpgs/280060/1 "2009-01-22T07:27:51Z")

</div>

i followed the kirupa tutorial on building an external image loader, and modified it to work with back/next buttons to load a range of images. everything works fine, but the problem is after a few cycles through the images, the site starts to lag. i believe the cause is a stack of images that grows as they are loaded. i have been trying to use removeChild and removeChildAt the previous image when the new image is loaded, but cannot get it to work. any help would be greatly appreciated.

```auto
var imageLoader:Loader;
var imageNumber:Number=1;
var imageCount:Number=14;

function loadImage(url:String):void {
    // Set properties on my Loader object
    imageLoader = new Loader();
    imageLoader.load(new URLRequest(url));
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}

loadImage("stills/still"+imageNumber+".jpg");

function imageLoaded(e:Event):void {
    // Load Image
    imageHolder.addChild(imageLoader);
}

function prevImage(evt:MouseEvent):void {
    if (imageNumber==1) {
        imageNumber=imageCount;
        loadImage("stills/still"+imageNumber+".jpg");
    } else {
        imageNumber--;
        loadImage("stills/still"+imageNumber+".jpg");
    }
}

function nextImage(evt:MouseEvent):void {
    if (imageNumber==imageCount) {
        imageNumber=1;
        loadImage("stills/still"+imageNumber+".jpg");
    } else {
        imageNumber++;
        loadImage("stills/still"+imageNumber+".jpg");
    }
}

prev_btn.addEventListener(MouseEvent.CLICK, prevImage);
next_btn.addEventListener(MouseEvent.CLICK, nextImage);

```
