I mean if you had to have the buttons onscreen before and you couldn't generate them with code --
Code:
var currentStr:String = "";
var tot:Number = 0;
var buttons:Array = new Array();
for (var i:Number=0;i<10;i++) {
buttons.push(root["bt"+i]);
buttons[buttons.length-1].name = String(i);
}
var operators:Array = ["+","-","/","*"];
for each (var o:String in operators) {
buttons.push(root["bt"+o]);
buttons[buttons.length-1].name = o;
}
for each (var b:MovieClip in buttons) {
b.addEventListener(MouseEvent.CLICK,this.gotPress,false,0,true);
}
function gotPress(evt:MouseEvent):void {
//something like this; numeric inputs are added to the string
if (!isNaN(Number(evt.target.name))) {
//literally tacked on at the end of the string as a substring.
currentStr += evt.target.name;
} else {
//if no total exists,
!tot ? tot = Number(currentStr) : void;
//eval() is gone =\
switch (evt.target.name) {
case "+":
currentStr = String(Number(currentStr)+tot);
break;
case "-":
currentStr = String(tot-Number(currentStr));
//etc.
}
}
}
}
I just realized that won't work 'cause the operations are retroactive...uh...you'd just have to queue the last operation.
Whatever.
Point is use a loop to add your buttons and events