My coworker Todd Yard, just ran across a real interesting one.
Say you want to loop through an array. You generally go through it forwards:
[as]for(var i:Number = 0; i < arr.length; i++) { trace(i); }[/as] or backwards: [as]for(var i:Number = arr.length - 1; i >= 0; i–)
{
trace(i);
}[/as]
Array Looping 101, right? Works fine in AS1, AS2.
Enter AS3. Still works fine if i is typed to Number as above. Even works fine when i is typed to int.
Now let’s make i a uint. Whoa! Freeze! 15 second timeout! What happened? Think about it.
Say arr has one element.
First loop, i = 0 (length – 1). Trace 0.
Decrement i. If you are using ints or Numbers, i is now -1, the conditional fails and your loop exits. But in uints, there are no negative numbers. Decrement 0 and it rolls over to the maximum value of a uint, which is four billion something. That’s greater than or equal to zero, for sure, so the loop keeps going. Even if your machine was fast enough to execute four billion loops in one frame in under 15 seconds, once it hit zero again, it would start over at four billion. Result: hang, 15 second timeout.
Solution: use ints or Numbers when looping through an array backwards.