In attempting to transition from AS2 to AS3, I am now messing around with arrays. I’ve been able to get arrays to work for me for the most part, but now I’m stumped. When I have a bunch of buttons that will make a corresponding bunch of movieclips do something (that is buttons in one array, movieclips in another), I get an error code:
ReferenceError: Error #1056: Cannot create property i on flash.display.SimpleButton.
at arrayButtonsAS3_fla::MainTimeline/frame1()
I didn’t get this error when the buttons were also movieclips, but I would like to use regular old buttons from time to time; especially when converting older interactives from AS2 to AS3: something that is becoming occasionally necessary.
Here is the code of a little test animation I’m doing:
var aButtons:Array=new Array(btnZero,btnOne,btnTwo,btnThree,btnFour,btnFive,btnSix,btnSeven,btnEight,btnNine,btnTen,btnEleven,btnTwelve,btnThirteen,btnFourteen);
var aSquares:Array=new Array(mcSquare0,mcSquare1,mcSquare2,mcSquare3,mcSquare4,mcSquare5,mcSquare6,mcSquare7,mcSquare8,mcSquare9,mcSquare10,mcSquare11,mcSquare12,mcSquare13,mcSquare14);
var index:Number;
var indexNumber:Number;
for (var i:Number=0; i<aButtons.length; i++) {
if (this.aButtons.length==this.aSquares.length) {
index=i;
aButtons[index].i=index;
for (var j:Number = 0; j<aSquares.length; j++) {
if (this.i==j) {
openClip(j);
}
}
}
}
function openClip(num):void{
trace(aButtons[num].name);
trace(aSquares[num].name);
}