Numbers of dynamically created buttons

I have started to create my buttons dynamically. When doing so, I would like to have a number for each, that I can use to then call other things, such as text from an array, images, etc. All my assets in this file are numbered. For example, the button that I am creating with the following for loop, will have a string from an array, and a jpg that will load when it is clicked.

This is how I am creating the buttons.

for(var i:Number = 0; i < thumbs; i++){
var ref:MovieClip = thumb_scroller.all_thumbs[“thumb” + i];
ref.onRelease = function():Void {
clickAction();
}
};

For example, “thumb_scroller.all_thumbs.thumb5” will, when clicked, load a jpg, called 5.jpg and reference a string from an array, at the 5 place in that array. So, if I could somehow, send the number 5 as a parameter with the clickAction();, I could then do what I want. I had tried something like this clickAction(i); but it did now work, because i got updated until the for loop was done and so had the same value for all buttons created by it. How is this done? Is there a way to create dynamic variable that I can send as a parameter with the clickAction()?

Thanks a lot. Any help would be greatly appreciated!!!