Dynamic buttons and listeners

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

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:


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