I have a ship on stage but I can’t move the ship with keyboard
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class Ship extends MovieClip {
public var shipSpeed:uint = 3;
public function Ship () {
addEventListener(Event.ENTER_FRAME,shipEnterFrame);
}
private function shipEnterFrame(event:Event):void {
addEventListener(KeyboardEvent.KEY_DOWN,gameKeyDown);
}
private function gameKeyDown(event:KeyboardEvent):void {
switch(event.keyCode) {
case Keyboard.UP :
y -= shipSpeed;
break;
case Keyboard.DOWN :
y += shipSpeed;
break;
case Keyboard.RIGHT :
x += shipSpeed;
break;
case Keyboard.LEFT :
x -= shipSpeed;
break;
case Keyboard.SPACE :
Fire();
break;
}
}
public function Fire () {
var missile:Missile = new Missile();
missile.x = x + 50;
missile.y = y + 2 ;
addChildAt(missile,numChildren - 1);
}
}
}