You're right that this can be caused by trying to remove a child twice, and you're setting eligableForRemove
after you call removeSelf()
, so removeSelf()
doesn't see the updated value.
However, I think the problem is that you're removing the bullet in removeLaser()
, but not telling the bullet that it has died, so it keeps running the loop, and eventually it goes out of bounds and tries to remove itself again.
You should be able to get rid of eligableForRemove
, and just change removeLaser()
to:
function removeLaser(idx:int)
{
(bullets[idx] as Bullet).removeSelf();
bullets.splice(idx,1);
}
(Or if bullets
is a Vector.<Bullet>
you can just do bullets[idx].removeSelf()
, as the runtime already knows it's a Bullet
.)