Anderson
Anderson

Reputation: 101

AS3 Button reference in an array

I have two buttons that are in a movieclip, how can I reference them like I have done with the 2 buttons below so that they can be added into an array?

container.anotherButton and container.anotherButton2 are the buttons I want to add to the array.

var agreeButton:SimpleButton;
var disagreeButton:SimpleButton;

var buttonArray:Array = new Array(agreeButton, disagreeButton);

for (var i:int = 0; i < buttonArray.length; i++) {    
   buttonArray[i].addEventListener(MouseEvent.CLICK, mouseClick);
}

Upvotes: 0

Views: 149

Answers (1)

Danny Birch
Danny Birch

Reputation: 603

I am not sure what the question is, I think this is what you need.

var buttonArray:Array = new Array(container.anotherButton, container.anotherButton2);

The reference will hold even if you move the container/buttons.

Upvotes: 2

Related Questions