Creating dynamic buttons?

im trying to dynamically create buttons…here’s an example scenario ->
off stage is a movie clip called “originalButton_mc”
I want to use a loop to duplicate this movie clip 25 times, and each one should be able to perform a unique onRelease function

ex.


for (i = 0; i<25; i++) {
    var newButton_mc = originalButton_mc.duplicateMovieClip("button"+i, i+1);
    newButton_mc._y = i*22;
    newButton_mc._x = 10;
    
    newButton_mc.onRelease = function() {
        trace(i);
    };
}

the problem with the above code is that when I click my new buttons it always traces 25…because, clearly - my code is wrong, and the onRelease is getting rewritten for each button - hence its left with the last i … 25.

Any clues on how I should be doing this so it works right?