Picking tiles

We said we are going to pick tiles with a mouse click. To manage mouse events such as clicks, movements, and rollovers, AS3 provides a dedicated class called MouseEvent. The first thing we need to do is to import this new class.

Import it before main class declaration, in the code delimited by // importing classes just like you imported Sprite class:

// importing classes
import flash.display.Sprite;
import flash.events.MouseEvent;
// end of importing classes

MouseEvent class is contained in the flash.events package, that's why I had to import another package.

Now you are ready to handle mouse events. Modify the tile placing loop (the code between // tile placing loop and // end of tile placing loop) this way:

// tile placing loop ...

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.