TypeError: Error #1009: Cannot access a property or method of a null object reference.
Hello, I have a problem with my ActionScript code. I have an object called carMove which is moved to the right using the arrow key. When this object hits an object called hitObject, I want it to display "Continue". This all works correctly but i'm getting a constant loop message.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at HistoryOfSport_fla::MainTimeline/loop()
I think the problem occurs as soon as the carMove hits the object.
Any help please ?
Here is my code -
stage.focus = this;
import flash.events.KeyboardEvent;
import flash.events.Event;
var right:Boolean = false;
Continue.visible = false;
stage.addEventListener( KeyboardEvent.KEY_DOWN, keydown);
stage.addEventListener( KeyboardEvent.KEY_UP, keyup);
stage.addEventListener(Event.ENTER_FRAME, loop);
function keydown(e:KeyboardEvent):void
{
switch ( e.keyCode )
{
case 39 : right = true;{
}
break;
}
if (right) { carMove.x += 20 ; }
carMove.targetsecondObjectMc.rotation += 20;
carMove.targetcrownMc.rotation += 20;
}
if (x> 949.2) {
gotoAndStop(3);
}
function keyup(e:KeyboardEvent):void
{
switch ( e.keyCode )
{
case 39 : right = false;
break;
}
}
function loop (e:Event) :void
{
if ( carMove.hitTestObject( hitObject ) )
{
carMove.visible = false;
Continue.visible = true;
trace(carMove);
}
}
//Adding an event Listener Continue button.
Continue.addEventListener( MouseEvent.MOUSE_UP, ContinueNext );
//Function for when button is pressed.
function ContinueNext( e:MouseEvent ):void
{
//Go to frame 3.
gotoAndStop(3);
}