# For Loop onRelease function \[AS2, Flash CS3\]

**URL:** <https://forum.kirupa.com/t/for-loop-onrelease-function-as2-flash-cs3/311702>\
**Category:** flash\
**Created:** [July 14, 2010, 12:46pm UTC](https://forum.kirupa.com/t/for-loop-onrelease-function-as2-flash-cs3/311702 "2010-07-14T12:46:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndyA](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@AndyA](https://forum.kirupa.com/u/AndyA)\
**Post date:** [July 14, 2010, 12:46pm UTC](https://forum.kirupa.com/t/for-loop-onrelease-function-as2-flash-cs3/311702/1 "2010-07-14T12:46:02Z")

</div>

Hi everyone,

I have another question about my For loop. I am designing and coding a navigation menu at the moment, and so far I have got the button instances to duplicate for each of the menu items, and set widths, positioning values and RollOver/RollOut functions. However, I would ideally like to include the onRelease button functions in the for loop too - as they are all the same apart from the variable “i”. Here is the code snippet:

```auto
for (i=1;i<(_root.noofmenuitems+1);i++){
	
	duplicateMovieClip("mc", "mc"+i, i);
	
	...

	this["mc"+i].onRelease = function(){
		_root.currentnumber = *;
		trace("test "+*);
	}
}

```

Now my problem is that by the time the onRelease function is called, the for loop has been completed and the value of i returned is the last i value from the loop (\_root.noofmenuitems+1). The this[“mc”+i] part obviously works, because the trace function is called when I click any of the menu items.

The problem is that I have 6 menu items, and when I click any of them, the trace function returns “test 7” - not the corresponding i values for each button.

Is there any way that I can solve this?

Thanks in advance for any replies,  
Andy 🙂
