[Flash8]Help needed with button actions at runtime

Sorry, this question might be a typical nooby question. I use flash in my job rather than having flash as a job if you know what I mean.

I am creating a set of buttons at runtime and I want each of them to have a different function.

Roughly speaking I am doing something along the following lines

for(var i=0; i<howManyButtons; i++){
var sname = [“myButton”+i];
this.createEmptyMovieClip(sname, this.getNextHighestDepth());

and then I go ahead and draw the buttons using lineTo etc etc.

My problem comes when I want to assign a different function to each of the buttons, still within the “for” loop, for example

this[sname].onRelease = function (){
gotoAndStop(i+2);
varText = theText*;}
}

This doesn’t work as the button function is still looking to see what “i” is when it is released, rather than having an absolute value for either of the parameters. How do I make each function unique and yet fixed?