Skip to content

Instantly share code, notes, and snippets.

@alecmce
Created October 16, 2011 11:26
Show Gist options
  • Save alecmce/1290782 to your computer and use it in GitHub Desktop.
Save alecmce/1290782 to your computer and use it in GitHub Desktop.
int/uint madness
package
{
import flash.display.Sprite;
[SWF(backgroundColor="#FFFFFF", frameRate="60", width="800", height="600")]
final public class Test extends Sprite
{
public function Test()
{
var a:uint = 3;
var b:int = 3;
trace("actual values:");
if (a < 0)
{
trace("a is int");
}
else
{
a = -a;
if (a < 0)
trace("a is int");
else
trace("a is uint");
a = -a;
}
if (b < 0)
{
trace("b is int");
}
else
{
b = -b;
if (b < 0)
trace("b is int");
else
trace("b is uint");
b = -b;
}
trace("but put this test into a method everything's an int!:");
test(a, "a");
test(b, "b");
}
private function test(value:*, label:String):void
{
if (value < 0)
{
trace(label + " is int");
}
else
{
value = -value;
if (value < 0)
trace(label + " is int");
else
trace(label + " is uint");
value = -value;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment