onPress event problem

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.