# Problem With Functions and Arrays in Loops

**URL:** <https://forum.kirupa.com/t/problem-with-functions-and-arrays-in-loops/212451>\
**Category:** flash\
**Created:** [January 11, 2007, 5:55am UTC](https://forum.kirupa.com/t/problem-with-functions-and-arrays-in-loops/212451 "2007-01-11T05:55:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonyb48](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@tonyb48](https://forum.kirupa.com/u/tonyb48)\
**Post date:** [January 11, 2007, 5:55am UTC](https://forum.kirupa.com/t/problem-with-functions-and-arrays-in-loops/212451/1 "2007-01-11T05:55:02Z")

</div>

I have an array of movie clips and an array of links. I want to assign the links to the movie clips. It works fine without a loop. The working code follows. But it says the file is undefined when I attempt to replace the last 9 lines of code with:  
for (m=0;m\<3;m++) {  
movieArray[m].onRelease = function (m) {  
getURL(linksArray[m]);  
}  
}

Here is the working code. How do I use a loop for the last block? – the real project has at least 24 movies and links.

* * *

//Make a batch of empty movie clips  
\_root.holder1\_mc.createEmptyMovieClip(“imageHolder1\_mc”,1);  
\_root.holder1\_mc.imageHolder1\_mc.createEmptyMovieClip(“image”,51)

\_root.holder1\_mc.createEmptyMovieClip(“imageHolder2\_mc”,2);  
\_root.holder1\_mc.imageHolder2\_mc.createEmptyMovieClip(“image”,52)

\_root.holder1\_mc.createEmptyMovieClip(“imageHolder3\_mc”,3);  
\_root.holder1\_mc.imageHolder3\_mc.createEmptyMovieClip(“image”,53)

//put images in the movie clips  
\_root.holder1\_mc.imageHolder1\_mc.image.loadMovie(“hmr/thumbs/abc001.jpg”)  
\_root.holder1\_mc.imageHolder2\_mc.image.loadMovie(“hmr/thumbs/abc002.jpg”)  
\_root.holder1\_mc.imageHolder3\_mc.image.loadMovie(“hmr/thumbs/abc003.jpg”)

//position the movie clips  
\_root.holder1\_mc.imageHolder1\_mc.\_x=7;  
\_root.holder1\_mc.imageHolder2\_mc.\_x=64;  
\_root.holder1\_mc.imageHolder3\_mc.\_x=121;

//Array of links (in the real project these are read from an external file)  
\_global.linksArray = new Array();  
linksArray = [“[http://www.tonybarre.com/matt",“http://www.tonybarre.com/travis”,"http://www.tonybarre.com/melissa](http://www.tonybarre.com/matt%22,%22http://www.tonybarre.com/travis%22,%22http://www.tonybarre.com/melissa)”];

//Array of movie clips (in the real project I create these with a loop)  
\_global.movieArray = new Array();  
movieArray = [\_root.holder1\_mc.imageHolder1\_mc, \_root.holder1\_mc.imageHolder2\_mc, \_root.holder1\_mc.imageHolder3\_mc]

//Assign the links to the corresponding movie clips (I want to put the following code into a loop  
movieArray[0].onRelease = function () {  
getURL(linksArray[0]);  
}  
movieArray[1].onRelease = function () {  
getURL(linksArray[1]);  
}  
movieArray[2].onRelease = function () {  
getURL(linksArray[2]);  
}
