I normally use this method
for(var i:int = 0; i < array.length; i++)
{
if(array[i].hitTestObject(randomObject)
{
array[i].parent.removeChild(array[i]);
array.splice(i, 1);
i--;
}
}
but I have recently found that you can also do this
for(var i:int = array.length-1; i > = 0; i--)
{
if(array[i].hitTestObject(randomObject)
{
array[i].parent.removeChild(array[i]);
array.splice(i, 1);
}
}
What is the method you use the most? and why?
Looping forward or backwards. Or perhaps you have a different method for looping through arrays.