Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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");}
Copy link to clipboard
Copied
still give the same error.
Copy link to clipboard
Copied
Can you show the "loop" event listener & its function code?
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
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");}
Copy link to clipboard
Copied
Still give the same error. May i know, the Scene 9 should be a movie clip or anything?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Yes it's correct, can you copy and paste the new error here?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Show the code in line number 81 in the loop function
Copy link to clipboard
Copied
Nothing in line 81 in loop function.
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
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!!!!!!!!!!!!!!
Copy link to clipboard
Copied
Great, you're welcome.
Copy link to clipboard
Copied
https://www.dropbox.com/s/fo99j67axiy6sa5/Mentadak.fla?dl=0
I take out the scene from my project.
Copy link to clipboard
Copied
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);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now