# Creating dynamic buttons?

**URL:** https://forum.kirupa.com/t/creating-dynamic-buttons/236879
**Category:** Uncategorized
**Created:** [August 24, 2007, 3:39pm UTC](https://forum.kirupa.com/t/creating-dynamic-buttons/236879 "2007-08-24T15:39:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![susancbk](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@susancbk](https://forum.kirupa.com/u/susancbk)
#### Post date: [August 24, 2007, 3:39pm UTC](https://forum.kirupa.com/t/creating-dynamic-buttons/236879/1 "2007-08-24T15:39:59Z")

</div>

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.

```auto

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?
