I am writing HitTestObject for my character:
(everycode is in ENTERFRAME section)
-for the Character:
if(bullet.bulletList.length>0)
for (var i:int = 0; i < bullet.bulletList.length; i++)
{ if(this.hitTestObject(bullet.bulletList[i]))
{
updateHP();
}
}
-for the enermy attack code:
bullet= new Bullet();
bulletList.push(bullet);
At the begining when there is not bullet in the stage, no error produced, but when the first bullet addchild to stage, an error like this appeared:
TypeError: Error #2007: 参数 hitTestObject 不能为空。(something's like hisTestOject cannot be empty)
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at com.miraclei::char/loop()
I think it’s because when the first bullet removeFromStage, the hitTestObject function found nothing in the bulletList, then error happened. I tried many way but still not ok!
Someone has solution for this?
If I’m reading this correctly, the trick is to iterate through your array of bullets in descending numeric order:
you won’t run into empty array positions this way.
hope this help!