# \[F8-AS2\]Dynamic array names in a for statement

**URL:** <https://forum.kirupa.com/t/f8-as2-dynamic-array-names-in-a-for-statement/245264>\
**Category:** flash\
**Created:** [November 28, 2007, 2:39am UTC](https://forum.kirupa.com/t/f8-as2-dynamic-array-names-in-a-for-statement/245264 "2007-11-28T02:39:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmo](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@bmo](https://forum.kirupa.com/u/bmo)\
**Post date:** [November 28, 2007, 2:39am UTC](https://forum.kirupa.com/t/f8-as2-dynamic-array-names-in-a-for-statement/245264/1 "2007-11-28T02:39:17Z")

</div>

Hi all, I have been a long time ‘lurker’ and have made great use of the site and information on it. But now I find myself in a bit of a jam which I am not able to find a way around myself (in a satisfactory way, atleast).

First I will explain what I’m trying to do, then I’ll post the code, and hopefully after that somebody will be kind enough to point out my mistake or a work around.

I am making an XML multiple-gallery flash site for a client. The chunk of code I am having trouble with is populating the thumbmails section of the site with all the pictures in all the galleries. The image paths are brought in and stored in an array - one array for each gallery’s image paths. The problem is that when I try to cycle through all the images to put them into movie clips (using a fore statement) I am having trouble dynamically addressing the arrays. \*\*More specifically, flash interprets them as strings, and does not evaluate the variables in them. \*\*I have tried all mess of things using eval, to no luck. So I will post up the code, and hopefully one of you geniuses will make me look dumb 🙂

```auto
function images(i){
 var temp:Number = eval("g"+i+"im.length");
 for (var r:Number=1; r<=temp; r++){
  eval("this.thumbHolder_mc.gallery"+i+"_mc").createEmptyMovieClip("thumb"+r+"_mc", 3550+r); 
  //doesn't work, but i would really like it to :)
  loadMovie("g"+i+"im["+(r-1)+"]", eval("this.thumbHolder_mc.gallery"+1+"_mc.thumb"+r+"_mc")
  //works, but not dyamic as gallery number is coded by hand.
  loadMovie(g1im[(r-1)], eval("this.thumbHolder_mc.gallery"+1+"_mc.thumb"+r+"_mc"));
 }
}

```

The argument images() takes is the gallery number (from another function). I have tried using eval() and trace to see what the problem is. Basically I can make it output the correct **STRINGS** , but flash will not convert the variables in the strings! So in the URL (first arg) of loadMovie it is seeing something like “g2im[3]” as a string, and not evaluating it to the value at index 4 of that array.

I hope all that made sense, help would be very much appreciated.

Thanks,  
Brian
