AS3: Understanding uint, int, Number

by troy on December 2, 2007

Curious if uint and int when typed were actually just Number, ran the following test. All int, uint, Number are typeof "number" and 'is Number' will return true, except when containing a decimal.

This isn't quite what I'd expect, I wouldn't expect a variable declared as Number to type as a int or uint or vice versa. So flash is doing some juggling under the Number covers...

var a:int = 1;
var b:uint = 2;
var c:Number = 3;
var d:Number = 4.5;
var args:Array = [ a, b, c, d];
 
function testNumber(a:Object):void{
trace(a + " ------");
trace(" isNumber?" + (a is Number));
trace(" isInt?" + (a is int));
trace(" isUint?" + (a is uint));
trace(" typeof number? " + (typeof(a) == "number"));
}
 
for(var i in args){
testNumber(args[i]);
}

OUTPUTS:
1 ------
isNumber?true
isInt?true
isUint?true
typeof number? true
2 ------
isNumber?true
isInt?true
isUint?true
typeof number? true
3 ------
isNumber?true
isInt?true
isUint?true
typeof number? true
4.5 ------
isNumber?true
isInt?false
isUint?false
typeof number? true

Previous post:

Next post: