I have some buttons named StrAdd, DexAdd, and ConAdd inside a movie clip. When you click on them, they all call the same function which tries to make some calculations on element 0 in an array on the main timeline based on the name of the button. The names of the arrays are StrArray, DexArray, and ConArray.
StrAdd.addEventListener(MouseEvent.CLICK, plus);
DexAdd.addEventListener(MouseEvent.CLICK, plus);
ConAdd.addEventListener(MouseEvent.CLICK, plus);
function plus(evt:MouseEvent):void {
trace(MovieClip(root)[evt.target.name.slice(0,-3) + "Array[0]"]);
}
What I've got there traces as "undefined". My syntax must be off. Does anyone know how to do it properly? Basically what I'm trying to do is make it so that if you click on the StrAdd button, the evt.target.name.slice(0,-3) part turns it into just Str because it chops off the last 3 letters, then that concatenates with "Array[0]" to it to make StrArray[0] which is in brackets to turn it into MovieClip(root).StrArray[0].