# attachMovie & functions

**URL:** <https://forum.kirupa.com/t/attachmovie-functions/214411>\
**Category:** flash\
**Created:** [January 28, 2007, 8:03pm UTC](https://forum.kirupa.com/t/attachmovie-functions/214411 "2007-01-28T20:03:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nutty](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@Nutty](https://forum.kirupa.com/u/Nutty)\
**Post date:** [January 28, 2007, 8:03pm UTC](https://forum.kirupa.com/t/attachmovie-functions/214411/1 "2007-01-28T20:03:01Z")

</div>

Hi guys, i’m creating a list of buttons for my website and herefore i’m using attachMovie to dublicate them.  
My code looks like this.

```auto
n=0; num=5;

while(n < num) {
 yPos=27+33*n; n++; attachMovie("button_mc", "button"+n ,n, {_x:0, _y:yPos});
 this["button"+n].onRollOver = function() { _root["button"+n].gotoAndPlay("_over"); };
 this["button"+n].onRollOut = function() { _root["button"+n].gotoAndPlay("_out"); };
}

```

When i launch i see 5 buttons. Now the problem is, when i hover the first button (on top) the one which is drawn last begins to “play”. The buttons are movieclips.

Basically, my question is: How can i add a function to each new button that is being made.

thx
