# Attach an actionscript to multiple buttons at once

**URL:** https://forum.kirupa.com/t/attach-an-actionscript-to-multiple-buttons-at-once/59813
**Category:** flash
**Created:** [August 4, 2004, 2:26am UTC](https://forum.kirupa.com/t/attach-an-actionscript-to-multiple-buttons-at-once/59813 "2004-08-04T02:26:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![alicethomas78](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@alicethomas78](https://forum.kirupa.com/u/alicethomas78)
#### Post date: [August 4, 2004, 2:26am UTC](https://forum.kirupa.com/t/attach-an-actionscript-to-multiple-buttons-at-once/59813/1 "2004-08-04T02:26:02Z")

</div>

I’m trying to find the way to attach the same actionscript to multiple  
buttons(over 100 buttons) at one time, instead of copying and pasting  
the actionscript in every frame. I have over 100 buttons as a seperate object in the library. In timeline, there are 100 keyframe, that each frame contains one button. Each instance is from one button. I don’t want to write a same actionscript in for every button object. Is there anyway to get  
around that?

thank you in advance,  
Nu

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2004, 9:12am UTC](https://forum.kirupa.com/t/attach-an-actionscript-to-multiple-buttons-at-once/59813/2 "2004-08-04T09:12:14Z")

</div>

make your button names like myButton0,myButton1,myButton2,myButton3…  
and than make a for loop like:

[AS]  
for(i=0;i\<100;i++){  
\_root[“myButton”+i].onRelease = function(){  
// YOUR ACTINSCRIPT 😉  
}  
}  
[/AS]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 5, 2004, 8:35am UTC](https://forum.kirupa.com/t/attach-an-actionscript-to-multiple-buttons-at-once/59813/3 "2004-08-05T08:35:10Z")

</div>

Thank you very much for your answer.

> [@e.s.x.s](#):
>
> make your button names like myButton0,myButton1,myButton2,myButton3…  
> and than make a for loop like:
> 
> [AS]  
> for(i=0;i\<100;i++){  
> \_root[“myButton”+i].onRelease = function(){  
> // YOUR ACTINSCRIPT 😉  
> }  
> }  
> [/AS]
