Placing the board to stage

Once the board is completed, you have to add it to the stage. First, you need to declare a variable to construct the board and add it to Display List.

Change your class level variables this way:

private var gameField:Array;
private var board:board_movieclip;

board is the variable name and board_movieclip is the type.

Let's add it to Display List. Add a new line to Main function:

public function Main() {
prepareField();
placeBoard();
}

Following the rule to split the code, we delegate to placeBoard function the dirty job and keep clean Main function.

This is placeBoard function:

private function placeBoard():void {
board=new board_movieclip();
addChild(board);
board.x=105;
board.y=100;
}

The function(s) just creates a board_movieclip ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.