Copy link to clipboard
Copied
this is the code :
function checkShoot():void
{
if (player.isShooting == true)
{
var bullet:Bullet = new Bullet(player.x,player.y,player.playerDir);
stage.addChild(bullet);
trace(player.playerDir);
player.isShooting = false;
}
}
function frameHandler(e:Event):void
{
if (platform.hitTestPoint(bullet.x + 31,bullet.y,true)) //it says the error is coming from here
{
trace("HIT PLATFORM:" + counter);
counter++;
}
I don't understand why this error is occurring. Please help me.
Copy link to clipboard
Copied
bullet is local to checkShoot. ie, it doesn't exist in frameHandler so that if statement will trigger a 1009 error
you can remedy that error by 'typing' bullet outside checkShoot, but they may cause other problems because you'll be using one reference (bullet) to identify more than one object (assuming you call checkShoot more than once).
Copy link to clipboard
Copied
Thanks I fixed it. I am adding the bullets to and array and hit testing the bullets in the array
Copy link to clipboard
Copied
you're welcome.
don't forget to loop through your array from end to start (not start to end) if you're removing array elements that are off-stage and no longer need to occupy memory.
p.s. please mark helpful/correct responses.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now