# addEventListener functions with a for loop?

**URL:** <https://forum.kirupa.com/t/addeventlistener-functions-with-a-for-loop/316290>\
**Category:** flash\
**Created:** [November 17, 2010, 8:32pm UTC](https://forum.kirupa.com/t/addeventlistener-functions-with-a-for-loop/316290 "2010-11-17T20:32:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonassus](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@bonassus](https://forum.kirupa.com/u/bonassus)\
**Post date:** [November 17, 2010, 8:32pm UTC](https://forum.kirupa.com/t/addeventlistener-functions-with-a-for-loop/316290/1 "2010-11-17T20:32:53Z")

</div>

I have four buttons with eventListeners that call four different  
functions. Each function name starts with the button name. like  
this:

```auto
btn1.addEventListener(MouseEvent.MOUSE_OVER, btn1function);
btn2.addEventListener(MouseEvent.MOUSE_OVER, btn2function);
btn3.addEventListener(MouseEvent.MOUSE_OVER, btn3function);
btn4.addEventListener(MouseEvent.MOUSE_OVER, btn4function);

```

I would like to use a for loop to setup the eventListerners with  
an array of the buttons. I would also like to define call the  
functions with in the addEventListener using the Array by  
concatenating the button name stored in the array with the  
rest of the function name (function) like this:  
btnArray\*+function which would give me all four functions.  
I know my problem is typing and that i need to maybe turn the  
function names in to a string in order do concatenate them.  
like this:

```auto
ar btnArray:Array = new Array(btn1,btn2,btn3,btn4);

for(var i = 0; i < 4; i++){
var b = (btnArray*);
b.addEventListener(MouseEvent.CLICK, b+function);
}

```

If this is possible would someone show me how.

Thanks
