Game Development Reference
In-Depth Information
The removeBlock function is similar to other remove style function we have written in this topic
already. We pass in a reference to the Block we want to remove from the board array
( blockToRemove ). We then have to iterate through both arrays until we locate the Block that
matches the Block ( blockToRemove) we want to remove. Our next job is to clean up as much as
possible behind this Block . We remove its EventListener , remove it from the display list with
removeChild(tempBlock) , call its dispose function (which will clean up the bitmapData ), and then
set its board position in the multidimensional array to null .
public function removeBlock(blockToRemove:Block):void {
for (var r:int = 0; r < board.length; r++) {
for (var c:int = 0; c < board[r].length; c++) {
tempBlock = board[r][c];
if (tempBlock == blockToRemove) {
tempBlock.removeEventListener(
CustomEventClickBlock.EVENT_CLICK_BLOCK, blockClickListener);
tempBlock.dispose();
removeChild(tempBlock);
board[r][c]= null;
}
}
}
}
In Figure 8-6, you can see what it might look like when blocks are added back into the board after
they have been removed from the screen.
Figure 8-6. Blocks added back onto the screen
Search WWH ::




Custom Search