package {
import flash.display.MovieClip;
import flash.sensors.Accelerometer;
import flash.events.Event;
import flash.ui.Keyboard;
import flash.ui.KeyLocation;
import flash.events.KeyboardEvent;
public class PlaneGame extends MovieClip {
public var level:Level1;
public var player:Plane;
public function PlaneGame() {
creategame();
createplayer();
addlisteners();
}
private function creategame():void
{
var level:Level1 = new Level1() ;
level.x=level.y=-0
addChild(level);
}
private function createplayer():void
{
var player:Plane = new Plane();
player.x=player.y = 100;
addChild(player);
}
private function addlisteners():void
{
stage.addEventListener(Event.ENTER_FRAME, movelevel, false, 0, false);
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveplayer, false, 1, false);
}
private function movelevel(e:Event):void
{
level.x-=10
}
private function moveplayer(k:KeyboardEvent):void
{
switch (k.keyCode)
{
case Keyboard.UP:
{
player.y -= 5;
break;
}
case Keyboard.DOWN:
{
player.y += 5;
break;
}
case Keyboard.LEFT:
{
player.x -= 5;
break;
}
case Keyboard.RIGHT:
{
player.x += 5;
break;
}
}
}
}
}
I'm going to remove the function "add listeners" from the constructor, add those listeners to the creategame and createplayer functions and then lead them to the resultant functions.