Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

TypeError: Error #1009: Cannot access a property or method of a null object reference.

New Here ,
May 05, 2015 May 05, 2015

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

}

TOPICS
ActionScript
767
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 05, 2015 May 05, 2015

That error is telling you that one or more of the objects referenced in the function loop isn't available where that function is written. So, if carMove, continue, or hitObject aren't on that frame then that's the origin of the error.

Translate
LEGEND ,
May 05, 2015 May 05, 2015

That error is telling you that one or more of the objects referenced in the function loop isn't available where that function is written. So, if carMove, continue, or hitObject aren't on that frame then that's the origin of the error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2015 May 05, 2015
LATEST

Thank you, managed to find the solution, just need to remove event listeners so they wouldn't carry on to the next frame.

event.currentTarget.removeEventListener(event.type,loop);

event.currentTarget.removeEventListener(KeyboardEvent.KEY_DOWN, keydown);  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines