# \[AS2\] need help with actionscript reading how many images are in folder externally

**URL:** <https://forum.kirupa.com/t/as2-need-help-with-actionscript-reading-how-many-images-are-in-folder-externally/294410>\
**Category:** flash\
**Created:** [August 13, 2009, 3:18pm UTC](https://forum.kirupa.com/t/as2-need-help-with-actionscript-reading-how-many-images-are-in-folder-externally/294410 "2009-08-13T15:18:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorne17](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lorne17](https://forum.kirupa.com/u/lorne17)\
**Post date:** [August 13, 2009, 3:18pm UTC](https://forum.kirupa.com/t/as2-need-help-with-actionscript-reading-how-many-images-are-in-folder-externally/294410/1 "2009-08-13T15:18:11Z")

</div>

Hello there,

I am in need of some help. I have successfully gotten my images to load externally and randomly into 4 different boxes on my stage.

My problem now is with the code I’m using, you HAVE to specify how many images there are in the actionscript. My goal is to allow for future updates to be done outside of flash and all we’d have to do is add or remove images in the external image folder.

Can anyone help enlighten my situation? Here’s the code I’m using:

```auto
//Variables
var currBox:Number = new Number();
var contentWidth:Number = box_0.content._width;
 //Image loader
this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
    with (target_mc) {
        if (_width>_height) {
            target_mc._xscale = target_mc._yscale=(contentWidth/target_mc._width)*100;
        } else {
            target_mc._xscale = target_mc._yscale=(contentWidth/target_mc._height)*100;
        }
        _x = (_root["box_"+currBox]._width-_width)/2;
        _y = (_root["box_"+currBox]._height-_height)/2;
    }
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
//Array containing pictures
var amount:Number = 15
var pics:Array = new Array();
for (var i = 0; i<amount; i++) {
    pics* = "SplashImages/image"+i+".jpg";
}
//Keep only 4 images
while (pics.length>4) {
    pics.splice(random(pics.length), 1);
}
//Load each image randomly into one of the four boxes
if (pics.length<5) {
    for (var i = 0; i<4; i++) {
        var r:Number = random(pics.length);
        currBox = i;
        image_mcl.loadClip(pics[r], _root["box_"+i].content);
        pics.splice(r, 1);
    }
}

```

Thanks,  
Lorne
