Hey all...
I'm trying to script a really simple celluar automation program like this. I am not new to programming at all, but this is my first experience with Actionscript.
Background:
The stage is 400x400 pixels. I have a 20x20 2D array (Named "grid") that stores 0s and 1s. The 2D array is traversed with two nested for loops. A black square (A movie clip with the class name "Block") will be created and placed depending on its indexes in the array (Offset by 20 pixels for each index value). Each child is given the name "tile"+i+"x"+j. For example, if a block is being displayed in positon (5,3) on the grid, the child's name would be "tile5x3"
The problem:
I can create the blocks no problem (Thanks for the help jmtb02), but I've no idea how to remove them. Since these blocks will be coming and going in this program, that's a big problem.
The code snippet:
I believe this has everything you need to see. Let me know if you need to see more. Keep in mind that this code works just fine. I just don't have a clue on how to take this next step. I see functions floating around like "getChildByName" but I'm not sure how to use it properly.
function createBlocks():void {
var currBlock:MovieClip;
for (var i:int=0; i<20; i++) {
for (var j:int = 0; j<20; j++) {
if (grid[j][i]==1) { // If there is a 1 in the array right here, place the object
currBlock = new Block();
currBlock.x = 20*i;
currBlock.y = 20*j;
currBlock.name = "tile"+i+"x"+j;
//trace(currBlock.name);
addChild(currBlock);
}
else{// If there's a 0 here, remove any object that would be here.
//How do I remove it?
}
}
}
}
Here is a screenshot of the program working so far.