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

ActionScript 3 - cannot move to the next scene.

Explorer ,
Dec 12, 2015 Dec 12, 2015

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at CompangleComplete_fla::MainTimeline/loop()[CompangleComplete_fla.MainTimeline::frame119:205]

I got this error.

When the player touch the "black rectangle", supposed to move to the next scene.

I try to check where is the problem, then I try this

if(endpoint==false){
if(player.hitTestObject(back.other)){

endpoint==true;
trace("next scene");}

the code run without error.

But then I try this,

if(endpoint==false){
if(player.hitTestObject(back.other)){

endpoint==true;
gotoAndPlay(2, "Scene 9");}

I got error like above.

The code for my gotoAndPlay(2, "Scene 9") is wrong. how i should change it?

masalah.jpg

TOPICS
ActionScript
1.3K
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 12, 2015 Dec 12, 2015

Correct the code and try:

if(endpoint==false){
if(player.hitTestObject(back.other)){

endpoint=true;
trace("next scene");}

the code run without error.

But then I try this,

if(endpoint==false){
if(player.hitTestObject(back.other)){

endpoint=true;
gotoAndPlay(2, "Scene 9");}

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
Explorer ,
Dec 12, 2015 Dec 12, 2015

still give the same 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
Enthusiast ,
Dec 12, 2015 Dec 12, 2015

Can you show the "loop" event listener & its function code?

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
Explorer ,
Dec 12, 2015 Dec 12, 2015

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void{

  if(back.collisions.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){

  //trace("leftBumping");

  leftBumping = true;

  } else {

  leftBumping = false;

  }

  if(back.collisions.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){

  //trace("rightBumping");

  rightBumping = true;

  } else {

  rightBumping = false;

  }

  if(back.collisions.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){

  //trace("upBumping");

  upBumping = true;

  } else {

  upBumping = false;

  }

  if(back.collisions.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){

  //trace("downBumping");

  downBumping = true;

  } else {

  downBumping = false;

  }

  if(leftPressed){

  xSpeed -= speedConstant;

  player.scaleX = -1;

  } else if(rightPressed){

  xSpeed += speedConstant;

  player.scaleX = 1;

  }

  if(leftBumping){

  if(xSpeed < 0){

  xSpeed *= -0.0001;

  }

  }

  if(rightBumping){

  if(xSpeed > 0){

  xSpeed *= -0.0001;

  }

  }

  if(upBumping){

  if(ySpeed < 0){

  ySpeed *= -0.0001;

  }

  }

  if(downBumping){ //if we are touching the floor

  if(ySpeed > 0){

  ySpeed = 0; //set the y speed to zero

  }

  if(upPressed){ //and if the up arrow is pressed

  ySpeed = jumpConstant; //set the y speed to the jump constant

  }

  //DOUBLE JUMP

  if(upReleasedInAir == true){

  upReleasedInAir = false;

  }

  if(doubleJumpReady == false){

  doubleJumpReady = true;

  }

  } else { //if we are not touching the floor

  ySpeed += gravityConstant; //accelerate downwards

  //DOUBLE JUMP

  if(upPressed == false && upReleasedInAir == false){

  upReleasedInAir = true;

  //trace("upReleasedInAir");

  }

  if(doubleJumpReady && upReleasedInAir){

  if(upPressed){ //and if the up arrow is pressed

  //trace("doubleJump!");

  doubleJumpReady = false;

  ySpeed = jumpConstant; //set the y speed to the jump constant

  }

  }

  }

  if(endpoint==false){

  if(player.hitTestObject(back.other)){

  endpoint=true;

  gotoAndPlay(1,"Scene 9");

  }

  }

  

  if(xSpeed > maxSpeedConstant){ //moving right

  xSpeed = maxSpeedConstant;

  } else if(xSpeed < (maxSpeedConstant * -1)){ //moving left

  xSpeed = (maxSpeedConstant * -1);

  }

  xSpeed *= frictionConstant;

  ySpeed *= frictionConstant;

  if(Math.abs(xSpeed) < 0.5){

  xSpeed = 0;

  }

  scrollX -= xSpeed;

  scrollY -= ySpeed;

  back.x = scrollX;

  back.y = scrollY;

  sky.x = scrollX * 0.2;

  sky.y = scrollY * 0.2;

  if( ( leftPressed || rightPressed || xSpeed > speedConstant || xSpeed < speedConstant *-1 ) && downBumping){

  animationState = "running";

  }

  else if(downBumping){

  animationState = "idle";

  } else {

  animationState = "jumping";

  }

  if(player.currentLabel != animationState){

  player.gotoAndStop(animationState);

  }

}

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 12, 2015 Dec 12, 2015

If you have any EnterFrame event listener remove it before you go to another scene:

if(endpoint==false){

if(player.hitTestObject(back.other)){

endpoint=true;

removeEventListener(Event.ENTER_FRAME, loop);
gotoAndPlay(2, "Scene 9");}

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
Explorer ,
Dec 12, 2015 Dec 12, 2015

Still give the same error. May i know, the Scene 9 should be a movie clip or anything?

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
Explorer ,
Dec 12, 2015 Dec 12, 2015

anto.JPG

Let say, this is my scene 9, frame 1.

I change from the code,

gotoAndPlay(1, "Scene 9");

Then, I saved the black rectangle in layer 1, frame 1.

then, turn it into movie Clip with instances name is lol

My Scene 9 is correct right?


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 12, 2015 Dec 12, 2015

Yes it's correct, can you copy and paste the new error here?

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
Explorer ,
Dec 12, 2015 Dec 12, 2015

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

  at CompangleComplete_fla::MainTimeline/loop()[CompangleComplete_fla.MainTimeline::frame119:181]

The same 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
Enthusiast ,
Dec 13, 2015 Dec 13, 2015

Show the code in line number 81 in the loop function

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
Explorer ,
Dec 13, 2015 Dec 13, 2015

mentah.jpg

Nothing in line 81 in loop function.

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 13, 2015 Dec 13, 2015

If you removed the loop event listener you should not get any error!

Make sure that you're removing the event listener before the gotoAndStop method

if(endpoint==false){

if(player.hitTestObject(back.other)){

endpoint=true;

removeEventListener(Event.ENTER_FRAME, loop); remove first
gotoAndPlay(2, "Scene 9"); then go to another scene

}

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
Explorer ,
Dec 13, 2015 Dec 13, 2015

okay. Thank you so much......

I change this code

if(endpoint==false){

if(player.hitTestObject(back.other)){

endpoint=true;

removeEventListener(Event.ENTER_FRAME, loop); remove first
gotoAndPlay(2, "Scene 9"); then go to another scene

}

into the very last of the line of loop function.... and it is work......

Thank you so much!!!!!!!!!!!!!!

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

Great, 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
Explorer ,
Dec 13, 2015 Dec 13, 2015
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 13, 2015 Dec 13, 2015

It's working well!

add this code on the line 55, it'll go to the scene 2 after 2 seconds without any error:

var endpoint:Boolean = false;

setTimeout (function (){    endpoint=true;

                            removeEventListener(Event.ENTER_FRAME, loop);

                            gotoAndStop(1,"Scene 2");}, 2000);

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