Categories Displayed in Flash

AS3: Understanding uint, int, Number

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...

  1.  
  2. var a:int = 1;
  3. var b:uint = 2;
  4. var c:Number = 3;
  5. var d:Number = 4.5;
  6. var args:Array = [ a, b, c, d];
  7.  
  8. function testNumber(a:Object):void{
  9. trace(a + " ------");
  10. trace(" isNumber?" + (a is Number));
  11. trace(" isInt?" + (a is int));
  12. trace(" isUint?" + (a is uint));
  13. trace(" typeof number? " + (typeof(a) == "number"));
  14. }
  15.  
  16. for(var i in args){
  17. testNumber(args[i]);
  18. }
  19.  

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

Comments are closed.