Copy link to clipboard
Copied
Hi guys i am trying to connect "scene 1" to "scene 2"
Then this ERROR comes out >>> Cannot access a property or method of a null object reference.
You guys can check my Flash File at >>> http://www.filedropper.com/egg
Please help. When I only run the Scene 2 it plays but when i tried to connect it with scene 1. An ERROR comes out .
Copy link to clipboard
Copied
It takes a moment for the things in scene 2 to settle down. You should wait one frame before setting up the enterframe function, or, in the enterframe function check to see if the bgA is ready yet. Like:
function onenter(e:Event):void {
if(bgA==null) return;
It's very strange to have two enterframe listeners. Not sure if it will work in all cases, so you might want to combine those two functions.
Copy link to clipboard
Copied
The other one is onenters it is for the egg that adds life.
The onenter is for the enemy/hurdle.
I input the code that you gave me but it still has the Cannot access a property or method of a null object reference. error.
Copy link to clipboard
Copied
You added both listeners to the stage. Can you add the egg enterframe listener to the egg?
As for the error, if you still see it you may have entered it in the wrong place.
If you go into publishing settings you can set the allow debugging option (it's under the advanced settings), then you will be told the line number where the error is happening.
Also, your button script needs to have this:
gotoAndStop(1, "Scene 2")
and not this:
gotoAndPlay(1, "Scene 1")
Copy link to clipboard
Copied
I have combined the "onenter" and "onenters" function. and it is working perfect.
function onenter(e:Event):void {
bgA.x += bgA.speed;
bgB.x += bgB.speed;
Ground.x += Ground.speed;
if (bgA.x <= 0 - (bgA.width - SWIDTH) ) {
bgA.x -= bgA.speed;
gameOver();
}
hero.x += hero.speed;
dy += gravity;
if (hero.y > 220) {
dy = 0;
canjump = true;
}
if (canjump) {
dy = hero.upval;
canjump = false;
}
hero.y += dy;
for (var i:int; i < objs.numChildren; i++) {
hurdle = (objs.getChildAt(i)) as Hurdle;
if (! hurdle.gotHit) {
if (hero.hitTestObject(hurdle)) {
hurdle.gotHit = true;
health.width -= (maxHealth / healthAmt);
if (health.width <= 0) {
gameOver();
}
}
}
}
for (var j:int; j < obj.numChildren; j++) {
life = (obj.getChildAt(j)) as Life;
if (! life.gotHit) {
if (hero.hitTestObject(life)) {
life.gotHit = true;
health.width += (maxHealth / healthAmt);
if (health.width <= 0) {
gameOverr();
}
}
}
}
}
Then i connected scene 1 to scene 2. then this came out
TypeError: Error #1009: Cannot access a property or method of a null object reference.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
Copy link to clipboard
Copied
I saw that error until I made the button be gotoAndStop instead of gotoAndPlay. Can you show your button script?
Copy link to clipboard
Copied
right_btn.addEventListener(MouseEvent.MOUSE_DOWN, doRight);
function doRight(e:Event):void {
hero.speed = 0;
bgA.speed = -4;
bgB.speed = -2.5;
Ground.speed = -5;
hero.gotoAndStop('walking');
}
jump_btn.addEventListener(MouseEvent.MOUSE_DOWN, doUp);
function doUp(e:Event):void {
hero.upval = -15;
}
These are the script for the two buttons: "jump_btn/doUp" and "right_btn/doRight"
You can see the full script on the link that I gave >> http://www.filedropper.com/egg
.