# Dynamic variable names

**URL:** https://forum.kirupa.com/t/dynamic-variable-names/300922
**Category:** Uncategorized
**Created:** [November 30, 2009, 5:30pm UTC](https://forum.kirupa.com/t/dynamic-variable-names/300922 "2009-11-30T17:30:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![samtherobot](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@samtherobot](https://forum.kirupa.com/u/samtherobot)
#### Post date: [November 30, 2009, 5:30pm UTC](https://forum.kirupa.com/t/dynamic-variable-names/300922/1 "2009-11-30T17:30:51Z")

</div>

I’ve got the following code that is adding an event listener to a movieclip. Wondering if I can do this in a loop as I have upward of 20 statements of basically the same thing.

```auto

btn_channel1.addEventListener(MouseEvent.CLICK, mute);
btn_channel2.addEventListener(MouseEvent.CLICK, mute);
btn_channel3.addEventListener(MouseEvent.CLICK, mute);
btn_channel4.addEventListener(MouseEvent.CLICK, mute);
btn_channel5.addEventListener(MouseEvent.CLICK, mute);
btn_channel6.addEventListener(MouseEvent.CLICK, mute);
btn_channel7.addEventListener(MouseEvent.CLICK, mute);
btn_channel8.addEventListener(MouseEvent.CLICK, mute);
btn_channel9.addEventListener(MouseEvent.CLICK, mute);

```

any thoughts?
