# Dynamic buttons and listeners

**URL:** <https://forum.kirupa.com/t/dynamic-buttons-and-listeners/258374>\
**Category:** flash\
**Created:** [April 23, 2008, 2:39pm UTC](https://forum.kirupa.com/t/dynamic-buttons-and-listeners/258374 "2008-04-23T14:39:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nevo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nevo/32/3473_2.png) [@Nevo](https://forum.kirupa.com/u/Nevo)\
**Post date:** [April 23, 2008, 2:39pm UTC](https://forum.kirupa.com/t/dynamic-buttons-and-listeners/258374/1 "2008-04-23T14:39:26Z")

</div>

Hello again  
Second cry for help in a week can’t be good. The move to AS3 not as easy as I assumed 🙂

I’m…

1. Importing content from XML to an array called mainData
2. extending the sprite and simpleButton class
3. making a button for each item imported (between 4 and 8)

This has all gone perfectly but I’m snagged at how to create a seperate listener for each button at the same time. What ever I do I end up with 7 buttons which all execute the same function. I assume I keep updatng the same listener each time I make a new button but can’t see a way around it… hence why I’m here again _looks around nervously_ :hangover:

```auto

trace('[Button setup]'); //setup main menu
//set number of items returned from XML
count = mainData.title.length;
//add a button to the main menu for each item
for (var i:int = 0; i < count; i++) {                
      var btn:TextButton = new TextButton(0xFFFFFF, 0x000000, data.title*, 50, 150);
      btn.y = (i*55)+255;
      btn.x = 8;
      btn.addEventListener(MouseEvent.CLICK, ***confused*** );

      MM.push(btn); //add button to main menu array.. maybe not :(
      contentHolder.addChild(btn);
}            

```

I tried adding the buttons to object and the function/listener but had no luck and Im back to square one.

Any help would be greatly appreciated!  
-Oli

//edit - Can’t type
