Copy link to clipboard
Copied
Hello adobe community, i cant fix an error in my game and cant find any solutions online, so if anyone here experienced , could u guys help me out. Im coding in adobe animate as3 btw. When ever i press reply or back to main menu button , i brings me this error.Need help asap pls
error-
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at game1obstacle_mc/update()
codes for moving obstacles-
var speedx = 10;
addEventListener(Event.ENTER_FRAME, update);
function update(e: Event) {
x = x - speedx;
speedx = speedx + 0.05;
if (x < -width) {
x = stage.stageWidth + width;
y = Math.random() * stage.stageHeight;
}
}
codes for main game-
import flash.events.Event;
import flash.events.MouseEvent;
import fl.motion.Color;
stop();
var mouseisdown = false;
var speed = 0;
var score = 0;
addEventListener(Event.ENTER_FRAME, mainloop);
stage.addEventListener(MouseEvent.MOUSE_DOWN, clicked);
stage.addEventListener(MouseEvent.MOUSE_UP, unclicked);
import flash.events.Event;
import fl.motion.Color;
function clicked(m: MouseEvent) {
mouseisdown = true;
}
function unclicked(m: MouseEvent) {
mouseisdown = false;
}
function mainloop(e: Event) {
score = score + 10;
output.text = "Score: " + score;
if (mouseisdown) {
speed -= 1.2;
} else {
speed += 1.2;
}
if (speed > 10) speed = 10;
if (speed < -10) speed = -10;
player.y += speed;
for (var i = 0; i < numChildren; i++) {
if (getChildAt(i) is game1obstacle_mc || getChildAt(i) is boundary) {
var b = getChildAt(i) as MovieClip;
if (b.hitTestObject(player)) {
for (var counter = 0; counter < 12; counter++) {
var boom = new Boom();
boom.x = player.x;
boom.y = player.y;
boom.rotation = Math.random() * 360;
boom.scaleX = boom.scaleY = 0.2 + Math.random();
addChild(boom);
}
player.visible = false;
removeEventListener(Event.ENTER_FRAME, mainloop);
gotoAndPlay(2);
}
}
}
}
Copy link to clipboard
Copied
click file>publish settings>swf>and tick 'permit debugging'. retest
the line number referencing a non-existent object will be in the error message. fix it.
but using x and y is probably the issue. use valid variable names, eg x1 and y1.
Copy link to clipboard
Copied
X and Y are the coordinates though, how do i declare x1 and y1 as variables for coordinates
Copy link to clipboard
Copied
Maybe it would be worth to invest in the "actionscript 3 bible" available on amazon or other good book shop...
Copy link to clipboard
Copied
Hi.
When you check for the end of the game and you send the main timeline to frame 2, probably your objects of type game1obstacle_mc and/or boundary are not available anymore, but they continue listening to the Event.ENTER_FRAME event and because of it trying to access the stage property, for example, that has no value if they aren't in the display list anymore.
So you should remove these Event.ENTER_FRAME listeners or the object itself before going to a different frame in the main timeline.
Copy link to clipboard
Copied
tick 'permit debugging'.