In Flash, I created a grid of 400 buttons with instance names c0 through c399.
In Actionscript, I'd like to create an array like this:
var myArray:Array = [c0,c1,c2,c3,c4,c5,c6];
all the way up to c399.
I wrote a for-loop to do the trick, but it doesn't seem to be working:
import flash.events.MouseEvent;
//create the array
var myArray:Array = [];
for (var i:int=0;i<399;i++){
var cletter:String = 'c';
var p:String = i.toString();
var newvalue:String = cletter + p;
var shizzle:Object = new SimpleButton();
myArray[i] = shizzle;
}
for each(var btn in myArray){
btn.addEventListener(MouseEvent.CLICK, onBtnClick);
}
function onBtnClick(event:MouseEvent):void{
cellinfo.gotoAndStop(event.target.name);
}
When I publish it, no errors show up and nothing happens when I click the buttons. However, if I use
var myArray:Array = [c0,c1,c2,c3,c4,c5,c6];
it does work! (for the first 7 buttons at least).
Also, when I put:
for (var i:int=1;i<6;i++){
var cletter:String = 'c';
var p:String = i.toString();
var newvalue:Object = cletter + p;
myArray[i] = newvalue;
}
it says:
TypeError: Error #1006: value is not a function. at PVproject1_fla::MainTimeline/frame1()
I just started working with AS3 + Flash and spent hours looking for a solution. Please help!