I keep getting tons of these messages in the output-window(not as error messages) when i run my game, in which you fire lasers at enemies(originality ftw i know) and a small explosion is created when the laser hits them. the game runs just as it should etc, but i find these messages really annoying, as well as they are telling me that there is something bad with my code, even though it obviously does what it is supposed to.
here they are:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at laser/::callExplosion()
at laser/::loop()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at smallExplosion/::removeSelf()
at smallExplosion/::loop()
and here is the actionscript(enemyList is an array in which all the enemies are stored):
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Stage;
public class laser extends MovieClip {
public function laser( x, y):void {
this.x = x;
this.y = y;
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function callExplosion():void {
var Small:smallExplosion = new smallExplosion(x,y);
stage.addChild(Small);
}
private function removeSelf():void {
removeEventListener(Event.ENTER_FRAME, loop);
if (stage.contains(this)) {
stage.removeChild(this);
}
}
private function loop(e:Event):void {
x += 35;
if (x > 700) {
removeSelf();
}
//ENEMY HIT TEST-------------------------------
for (var i:int = 0; i < spaceshooter.enemyList.length; i++){
if (this.hitTestObject(spaceshooter.enemyList[i].hit)==true){
callExplosion();
spaceshooter.enemyList[i].takeHit();
removeSelf();
}
}
}
}
}
and here is the as for the explosions:
package{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class smallExplosion extends MovieClip{
public function smallExplosion(x,y) {
rotation = Math.random() * 360;
this.x = x;
this.y = y;
scaleX=0.5;
scaleY=0.5;
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event) :void{
if (currentFrame == totalFrames)
{
removeSelf();
}
}
private function removeSelf():void {
removeEventListener(Event.ENTER_FRAME, loop);
if (stage.contains(this)) {
stage.removeChild(this);
}
}
}
}
it would be very helpful if someone could tell me what is wrong and what to do about it, thanks!