ForumsProgramming Forum[as3]looping through array & splice

2 10359
weirdlike
offline
weirdlike
1,299 posts
Prince

I normally use this method

for(var i:int = 0; i &lt 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 &gt = 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.

  • 2 Replies
Showing 136-135 of 2