Calling button instances created with XML data, Help??

Commenta 29th November , 2009
Hello everyone, this is my first post on this forum so please take it easy on me as I am sure that this will be a simple answer for most of you out there.

Here is what I am working with: I have dynamically added 4 buttons to the stage using XML data and a loop to place as many buttons as will allow per the data. Once the game begins, a MovieClip that I have also added to the stage will jump randomly from frames 1-16 and stop using a stage event listener. I need to have event-listeners on each of the buttons I have created using the XML data to check to see if the user has selected a correct answer. I had intended on using a function that would check to see which button was clicked and check to see what frame the movieClip was on when that button was clicked and judge right or wrong that way.

Now here is the issue I am having.

I do not know how to call to these buttons. More specifically how do I distinguish the "red" button from the "green" one. Since they were created dynamically they do not have instance names.

Here is my code for creating the buttons. The commented out sections are what I am having issues with. Any tips would be greatly appreciated.

function loadButton(e:Event):void {
//trace(evt.target.data);
buttonXML=new XML(e.target.data);
showButton(buttonXML);
}

function showButton(buttons:XML):void {
var buttonCount:int=buttons.button.length();
for (var q:int = 0; q< buttonCount; q++) {
var newButton:colorButton = new colorButton();
addChild(newButton);
newButton.x = 75+ ( q*(newButton.width + 25)+30);
newButton.y=375;
newButton.buttonMode=true;
newButton.mouseChildren=false;
newButton.buttonText_txt.text=buttons.button[q].buttonText;

stage.addEventListener(MouseEvent.CLICK, nextColor);
//newButton[0].addEventListener(MouseEvent.CLICK, checkRed);
//newButton[1].addEventListener(MouseEvent.CLICK, checkGreen);
//newButton[2].addEventListener(MouseEvent.CLICK, checkBlue);
//newButton[3].addEventListener(MouseEvent.CLICK, checkYellow);

}

}

Original post by Boulderheads

Lascia un Commento