Adding and controlling the spaceship

As usual we know we are going to use classes to manage both enter frame and mouse click events, so we'll import all the required classes immediately.

The spaceship is controlled with the mouse, but can only move along x-axis.

Without closing astro_panic.fla, create a new file and from New Document window select ActionScript 3.0 Class. Save this file as in the same path you saved astro_panic.fla. Then write:

package { import flash.display.Sprite; import; import; public class Main extends Sprite { private var spaceship:spaceship_mc; public function Main() { placeSpaceship(); addEventListener(Event.ENTER_FRAME,onEnterFrm); } private function placeSpaceship():void ...

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.