Key.isDown

Attach and Place the Ship

OK, if you've been following along with these tutorials, this shouldn't be much of a challenge. We're going to get this spaceship on the stage: Vertical center and about 100 pixels from the left side of the stage. We might want to change that later, so we'll get to work declaring variables:

var sH:Number = Stage.height;
var shipX:Number = 100;

Pretty standard... we declared the sH variable with a value equal to the height of the stage (Stage.height). We also declared the shipX variable with a value of 100.

Now we'll create a function to attach the ship to the stage, and set the x and y position. We'll call that function init:

var sH:Number = Stage.height;
var shipX:Number = 100;

function init () {
attachMovie("ship","ship",2000);
ship._x = shipX;
ship._y = sH/2;
}

Now we'll call the init function so it runs at the start of the movie:

var sH:Number = Stage.height;
var shipX:Number = 100;

init ();

function init () {
attachMovie("ship","ship",2000);
ship._x = shipX;
ship._y = sH/2;
}

That's it. Our ship should be centered vertically. Check to make sure it's working for you:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player