I have pasted my coding. Initially, I was accidentally in the frame 2 while writing the coding, but then I deleted the code file and recreate the file. But still, the problem persists. Can anyone help me with this code
public class firstGame extends MovieClip
{
public var mcPlayer:MovieClip;
private var leftKeyIsDown:Boolean;
private var rightKeyIsDown:Boolean;
public function firstGame()
{
//trace("First Game Loaded");
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
stage.addEventListener(Event.ENTER_FRAME, gameLoop);
}
private function gameLoop(e:Event):void
{
trace("Loaded");
}
private function playerControl():void
{
if (leftKeyIsDown == true)
{
mcPlayer.x -= 5;
}
if (rightKeyIsDown == true)
{
mcPlayer.x += 5;
}
}
private function keyUp(e:KeyboardEvent):void
{
if (e.keyCode == 37)
{
//left key released
leftKeyIsDown = false;
}
if (e.keyCode == 39)
{
//right key released
rightKeyIsDown = false;
}
}
private function keyDown(e:KeyboardEvent):void
{
if (e.keyCode == 37)
{
//left key released
leftKeyIsDown = true;
}
if (e.keyCode == 39)
{
//right key released
rightKeyIsDown = true;
}
}
}
and THE ERROR IS
TypeError: Error #1009: Cannot access a property or method of a null object reference. enter code here at firstGame/playerControl() at firstGame/gameLoop()
please help me with a solution