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.

Community Beginner ,
Dec 29, 2015 Dec 29, 2015

i'm making a simple game and i'm still learning as3 I want to go at the next frame but  get the null error. it is a maze game.


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

  at Senzanome_9_Scena1_fla::MainTimeline/stage_onEnterFrame()

here is the code

stop ();

next.visible=false;

var rightArrow:Boolean = false;

  var leftArrow:Boolean = false;

  var upArrow:Boolean = false;

  var downArrow:Boolean = false;

  var speed:int = 5;

  stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);

  stage.addEventListener(KeyboardEvent.KEY_UP, stage_onKeyUp);

  stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);

  function stage_onKeyDown(event:KeyboardEvent):void {

  if(event.keyCode == Keyboard.RIGHT) rightArrow = true;

  if(event.keyCode == Keyboard.LEFT) leftArrow = true;

  if(event.keyCode == Keyboard.UP) upArrow = true;

  if(event.keyCode == Keyboard.DOWN) downArrow = true;

  }

  function stage_onKeyUp(event:KeyboardEvent):void {

  if(event.keyCode == Keyboard.RIGHT) rightArrow = false;

  if(event.keyCode == Keyboard.LEFT) leftArrow = false;

  if(event.keyCode == Keyboard.UP) upArrow = false;

  if(event.keyCode == Keyboard.DOWN) downArrow = false;

  }

  function stage_onEnterFrame(event:Event):void {

  var rect:Rectangle = player.getBounds(this);

  var i:int = 0;

  var xBump:int = 0;

  var yBump:int = 0;

  if(rightArrow) {

  xBump = speed;

  for(i = 0; i < speed; i++) {

  if(maze.hitTestPoint(rect.right + i, player.y, true)) {

  xBump = i - 1;

  break;

  }

  }

  }

  if(leftArrow) {

  xBump = -speed;

  for(i = 0; i < speed; i++) {

  if(maze.hitTestPoint(rect.left - i, player.y, true)) {

  xBump = -i + 1;

  break;

  }

  }

  }

  if(upArrow) {

  yBump = -speed;

  for(i = 0; i < speed; i++) {

  if(maze.hitTestPoint(player.x, rect.top - i, true)) {

  yBump = -i + 1;

  break;

  }

  }

  }

  if(downArrow) {

  yBump = speed;

  for(i = 0; i < speed; i++) {

  if(maze.hitTestPoint(player.x, rect.bottom + i, true)) {

  yBump = i - 1;

  break;

  }

  }

  }

  player.x += xBump;

  player.y += yBump;

  pickUp();

function pickUp (){

  if (player.hitTestObject(coin1)) {

  coin1.x=1000

  }

  if (player.hitTestObject(coin2)) {

  coin2.x=1000

  }

  if (player.hitTestObject(coin3)) {

  coin3.x=1000

  }

  if (player.hitTestObject(coin4)) {

  coin4.x=1000

  }

  if (player.hitTestObject(coin5)) {

  coin5.x=1000

  }

  if (player.hitTestObject(coin6)) {

  coin6.x=1000

     {next.visible = true;}

  }


}

}


next.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_10);

function fl_ClickToGoToAndStopAtFrame_10(event:MouseEvent):void

{

  gotoAndStop(3);

}


TOPICS
ActionScript
825
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

Enthusiast , Dec 29, 2015 Dec 29, 2015

Or remove it at this point:

  if (player.hitTestObject(coin6)) {

stage.removeEventListener(Event.ENTER_FRAME, stage_onEnterFrame);

  coin6.x=1000

     next.visible = true;

  }

That will be better.

Translate
Community Beginner ,
Dec 29, 2015 Dec 29, 2015

I run the movie in debug mode and found the following point that causes that error :



if(maze.hitTestPoint(rect.left - i, player.y, true)) {

  xBump = -i + 1;

  break;

  }

Could you please help me to solve this problem?

Thanks for all help

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
Enthusiast ,
Dec 29, 2015 Dec 29, 2015

I think that "maze" movie clip is not visible to the main timeline, did you add it in another movie clip?

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
Community Beginner ,
Dec 29, 2015 Dec 29, 2015

no..  I create a maze at frame 1 and now i want to go at the next frame, but i can't.
what can i do?

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
Enthusiast ,
Dec 29, 2015 Dec 29, 2015

Remove the enter frame event listener:

function fl_ClickToGoToAndStopAtFrame_10(event:MouseEvent):void

{

stage.removeEventListener(Event.ENTER_FRAME, stage_onEnterFrame);

  gotoAndStop(3);

}

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
Enthusiast ,
Dec 29, 2015 Dec 29, 2015

Or remove it at this point:

  if (player.hitTestObject(coin6)) {

stage.removeEventListener(Event.ENTER_FRAME, stage_onEnterFrame);

  coin6.x=1000

     next.visible = true;

  }

That will be better.

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
Community Beginner ,
Dec 29, 2015 Dec 29, 2015

thaanks now it's works

Grazie mille

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
Enthusiast ,
Dec 29, 2015 Dec 29, 2015
LATEST

You're welcome

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