# Assign addEventListener to 52 Buttons!

**URL:** <https://forum.kirupa.com/t/assign-addeventlistener-to-52-buttons/308807>\
**Category:** Uncategorized\
**Created:** [April 30, 2010, 12:53pm UTC](https://forum.kirupa.com/t/assign-addeventlistener-to-52-buttons/308807 "2010-04-30T12:53:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pouradam](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@Pouradam](https://forum.kirupa.com/u/Pouradam)\
**Post date:** [April 30, 2010, 12:53pm UTC](https://forum.kirupa.com/t/assign-addeventlistener-to-52-buttons/308807/1 "2010-04-30T12:53:29Z")

</div>

Hi there! I am not an expert in Flash and my problem might looks silly.  
But anyway, my problem is that, I have 52 Button instances on Scene 1 as bellow:

B1 , B2 , B3 , … , B52

and I want to assign seperated actions for each of them.

The way I currently **CAN** do that is this:

B1.addEventListener(MouseEvent.MOUSE\_DOWN, B1F);  
B2.addEventListener(MouseEvent.MOUSE\_DOWN, B2F);  
B3.addEventListener(MouseEvent.MOUSE\_DOWN, B3F);  
.  
.  
.  
B52.addEventListener(MouseEvent.MOUSE\_DOWN, B4F);

But the way I **CANT** do this, is that I use a formula like WHILE for example, to do this for all of them together…

for example:

**var i:int = 1;**  
**var test:string;**  
**while (i\<53) {**  
**[COLOR=red]test[/COLOR] = “B” + i**  
\*\*[COLOR=red]test[/COLOR].addEventListener(MouseEvent.MOUSE\_DOWN, test + “F”); \*\*  
**i++;**  
**}**

But “**test.addEventListener(…**” does not work, and Flash searches for a function named “test” instead of working with the VALUE of “test”. hope it is not confusing?

What is the right way to do this in your opinion???

Any sort of help is really appreciated - Ali
