So I have only ever coded in AS2, and I am trying to create a tower-defence sort of game in AS3. In my main class I call this function:
private function createGrid():void
{
for (var a:int = 0; a < numCols; a++)
{
for (var b:int = 0; b < numRows; b++)
{
var testBlock:MovieClip = new block();
testBlock.name = "block_" + a + "_" + b;
testBlock.x = a * 20;
testBlock.y = b * 20;
addChild(testBlock);
}
}
}
That creates a grid on my main stage which works fine. Each block traces it’s name when you click it, all saying “block_x_y” relatively, for example “block_3_4”, x being the column they are in and y the row, (24 columns, 21 rows). The problem I run into is trying to do ANYTHING with the movieclips added dynamically, in AS2 I could just use:
_root["block_"+currentX+"_"+currentY].wall
“Wall” is a boolean each block has, so I’m trying to get the simplest things done in AS3 by using a function that I call on mouse cilck of a button:
private function LoadLevel(map:Array):void
{
trace(root["block_1_1"].x);
}
and sadly I cannot get this to work for the life of me. How can I possibly access or refer to movieclips added during runtime? I get this:
ReferenceError: Error #1069: Property block_14_11 not found on Main and there is no default value.
at block/onClickHandler()
Every time that I try to trace the object’s name, or X, or any value. I have searched everywhere and all I want is a simple method on accesing these, like using _root[“block_1_1”] was in AS2. I would greatly appreciate some help, as I said I am very new to AS3.