Making the bullet fly

To make the bullet fly, we have to define its speed and move it upwards. Then we'll remove it once it leaves the stage and reset isFiring to false to let the player fire again.

Add a constant to class level variables:

private const BULLET_SPEED:uint=5;
private var spaceship:spaceship_mc;
private var isFiring:Boolean=false;
private var bullet:bullet_mc;

BULLET_SPEED is the amount of pixels the bullet will fly at each frame. We won't manage upgrades or power-ups, so we can say its value will never change. That's why it's defined as a constant.

To manage bullet movement, we need to add some lines at the end of onEnterFrm function.

You may wonder why we are managing both the spaceship and the bullet inside the same class rather ...

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.