Hi everyboby, i need some help solving this error
Error #1009: Cannot access a property or method of a null object reference.
I’m creating a platform game where the character can fire bullets, these bullets are created when the space bar is pressed and added to an array.
They are then controlled by my moveBullets function below. This is called in the enter frame handler.
private function moveBullets():void
{
for(var i:int = 0; i < _bullets.length; i++)
{
//Move bullet
_bullets[i].x += _bullets[i].vx;
//check stage boundaries for bullet
if(_bullets[i].x + _bullets[i].width < 0
||_bullets[i].x > _stage.stageWidth)
{
this.removeChild(_bullets[i]);
_bullets[i] = null;
_bullets.splice(_bullets[i], 1);
i--;
}
//check collision with platforms
if(_bullets[i] != null
&& _bullets[i].hitTestObject(_platforms[1]))
{
this.removeChild(_bullets[i]);
_bullets[i] = null;
_bullets.splice(_bullets[i], 1);
i--;
}
}
}
The code works when only checking for the stage boudaries, but when I check for collisions with the platforms I get the #1009 error.
This error occurs when the bullet hits the platform and seems to be referring to this line of code
//Move bullet _bullets[i].x += _bullets[i].vx;
Any ideas what I’m doing wrong and how to fix it?
Please let me know if I need to give more info or I havent been clear
Thanks