# onPress event problem

**URL:** <https://forum.kirupa.com/t/onpress-event-problem/217492>\
**Category:** flash\
**Created:** [February 27, 2007, 2:53pm UTC](https://forum.kirupa.com/t/onpress-event-problem/217492 "2007-02-27T14:53:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![psasser](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@psasser](https://forum.kirupa.com/u/psasser)\
**Post date:** [February 27, 2007, 2:53pm UTC](https://forum.kirupa.com/t/onpress-event-problem/217492/1 "2007-02-27T14:53:32Z")

</div>

So inside of a for loop I dynamically attach a Movie Clip with a button. I want to give this movie clip an onPress event that uses the variable i from my loop.

dynButton.onPress = function ()  
{  
\_global.recordToDisplay = i;  
gotoAndPlay(5);  
}

However as the loop finishes i keeps incrementing and then when I click on the button it then evaluates i. Instead of evaluating it as “1” it evaluates as the last instance of i which is “3”. So I figured that I could create a variable each time I loop thourgh and assign that to \_global.recordToDisplay instead. So I tried this.

var \_root[“record” + i] = i;  
and then set  
\_global.recordToDisplay = \_root[“record” + i]; not working  
set(\_global.recordToDisplay, \_root[“record” + i]); also not working

Any suggestions here would be much appreciated.
