6.5.11

First Game OMG!

Yes well I tried to make a game a week ago. Here is the code:


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;
}
}
}


}

}


Not surprisingly, the code didn't work. I got two compiler errors. These are the errors:


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PlaneGame/movelevel()

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PlaneGame/movelevel()


What do I want to do with this, huh?


No comments:

Post a Comment