AS3 DisplayObject Container matching all elements with addChild() on criteria

Hey guys,

So I’m coding this minigame implementation where a sprite traverses tiles on a screen, and when he’s done traversing a tile, the tile “disappears” (its alpha decreases and it becomes a “wall” the player can not move onto). Now, simple enough. Here’s how I do it:

Make use of a traversing and traversed boolean arrays to store if a tile is currently being traversed, or if it isn’t, but it has been traversed. So, if traversing == 0 and traversed == 1, make the tile “disappear”. However, and here’s the weird part, if I just set the alpha to, say, 0.5 in this if statement, it sets the alpha on just the tile I traversed, whereas if I try to make it part of the wall as well (in the same if), every tile except the one I’ve traversed to becomes a wall.

Here’s part of the code (it happens in the enterFrame game loop):


const NUM_TILES = 15;

//Add MC for all the tiles
var tiles = new MovieClip();
addChildAt(tiles,5);
//Add tile0 to tile15 on stage to this MC
for (k = 0; k < NUM_TILES;k++){
	tiles.addChild(this["tile" + k])
}

//Loop through tiles, checking collision and changing traversing and traversed boolean arrays to check for how collision occurs
for (i=0;i<tiles.numChildren;i++){
	var tile:DisplayObject = tiles.getChildAt(i);
//If it's been traversed and is not being traversed ATM, set alpha to 0.5 and add to walls MC
	if (traversing* == 0 && traversed* ==1){
		tile.alpha=0.5;
                walls.addChild(tile);//This is what makes all tiles disappear
}
	if (character.hitTestObject(tile)){
		traversing* = 1;
		if (traversed* == 0){
		traversed* = 1;
		}
	}
	else {
		traversing* = 0;
	}
}


I’d give more code/the FLA, but it’s a bit of a mess, and I know the above section is the only thing that’s wrong.

So, if anyone can help me out, that’d be fantastic.

Best,

Alex