Type Error #1010 (an object is undefined and had no properties) when
removing child from an array
I get a type error in this function of an undefined object when i comment
out the if statements in the function the error goes away.
spartans is an array
bullets is an array
function loop(event:Event)
{
for (var bcount=0; bcount < bullets.length; bcount++)
{
if (bullets[bcount].x <= 1055)
{
bullets[bcount].x = bullets[bcount].x + bulletSpeed;
}
else
{
removeChild(bullets[bcount])
bullets.splice(bcount, 1)
if (bullets.length != 1)
{
bcount--;
}
}
}
for (var spcount=0; spcount<spartans.length; spcount++)
{
spartans[spcount].x = spartans[spcount].x - spartanSpeed;
if (bullets.length != 0)
{
if (bullets[bcount].hitTestObject(spartans[spcount]))
{
removeChild(spartans[spcount])
spartans.splice(spcount, 1)
removeChild(bullets[bcount])
bullets.splice(bcount, 1)
}
}
}
}
No comments:
Post a Comment