Here is what I am trying to do. Make a dynamic number of buttons on the stage. Place a BtnNum variable in each button so that when the button is clicked it will pass that BtnNum to a function. Here is my code so far
var BtnAmout = 5;
var Spacer = 5;
for(var i:Number=0;i<=BtnAmout;i++){
//I set Btn0-5 to the Btn movieclip in the lybrary
this[“Btn”+i] = new Btn();
//I space each Btn out onto the stage
this[“Btn”+i].x = Spacer+(this[“Btn”+i].widthi)+(Spaceri);
this[“Btn”+i].y = Spacer;
//I place each Btn onto the stage
addChild(this[“Btn”+i]);
//I create and set a variable BtnNum to the current number in the for loop
this[“Btn”+i].BtnNum = i;
//I have a text field in the Btn so I know what number the button it
this[“Btn”+i].NumText.text = i;
//Btn on click send the BtnNum variable to SayNumber to be traced out
this[“Btn”+i].addEventListener(MouseEvent.CLICK, SayNumber(i));
}
function SayNumber(i:String){
trace("Btn Clicked was "+i)
}
I know that if I use something like
this[“Btn”+i].addEventListener(MouseEvent.CLICK, function(e:MouseEvent){SayNumber(e, “Hello”)});
it will pass a variable but I want to make the variable dynamic and I am lost. I am new to as3 since a week ago. Any help would be amazing.