Content

i, for loop, uint and int in ActionScript 3

Thursday 14 February 2008 - Filed under Tips

Defining i:uint is not better than i:int since both of them take the same amount of memory. Besides, it’s risky to define i:unit because if i is accidentally assigned to a negative value it becomes a big positive int.

2008-02-14  »  5566

Talkback x 4

  1. Keith Peters
    14 February 2008 @ 7:33 am

    I often use uints. Not because of any memory or performance reasons, but because it documents the intention of the variable. You are stating, “this variable is an integer, and should never be negative.” The problem is, like you said, when you make it negative, it flops over. I think it would be better if it threw an exception if you tried to make it negative..

  2. Derek Vadneau
    14 February 2008 @ 11:32 am

    For a bit more detail on the subject, check out these entries:
    http://www.bit-101.com/blog/?p=908 (surprised kp didn’t mention it)
    http://tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/
    http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/

  3. Christian Cantrell
    14 February 2008 @ 2:47 pm

    I usually use uint, though I have had instances where I’ve had it become a huge positive number. I figure 4294967295 is just as big of a bug as -1, so I usually don’t worry about it.

    Christian

Share your thoughts

Re: i, for loop, uint and int in ActionScript 3







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

For spam filtering purposes, please copy the number 3714 to the field below: