# Function inside a for loop

**URL:** <https://forum.kirupa.com/t/function-inside-a-for-loop/73851>\
**Category:** Uncategorized\
**Created:** [December 21, 2004, 5:56am UTC](https://forum.kirupa.com/t/function-inside-a-for-loop/73851 "2004-12-21T05:56:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler](https://avatars.discourse-cdn.com/v4/letter/t/35a633/32.png) [@Tyler](https://forum.kirupa.com/u/Tyler)\
**Post date:** [December 21, 2004, 5:56am UTC](https://forum.kirupa.com/t/function-inside-a-for-loop/73851/1 "2004-12-21T05:56:55Z")

</div>

Hey everyone,

I have a function inside a for loop and in that function i am using the counter of the loop (the letter i) as a variable but it seems like inside the function the value of i gets reset.  
Here is my code:

siteMenu=[“Profile”,“My work”,“Links”];  
\_root.createEmptyMovieClip(“mainMC”,200);

for(i=0;i\<siteMenu.length;i++){  
\_root.createEmptyMovieClip(“MyButton”+i,100+i);  
\_root[“MyButton”+i].\_x=100;  
\_root[“MyButton”+i].\_y=100+(15_i);  
}  
\_root[“MyButton”+i].onRelease=function(){  
loadMovie(siteMenu_+".swf",“mainMC”);  
}  
}

The problem is how can i get around this thing so i can loadMovie according to the value of i.

Thanks for your help guys!
