开发者

Are Actionscript integers Numbers in the debugger?

I've stumble开发者_如何学运维d upon a strange thing in Flex. I created an integer variable:

var foo:int = 1;

And in the debugger it says foo is a Number with a value of 1.

It wasn't a biggie for me but seems Numbers are being sent instead of integers when doing remote service calls. What's happening here?


I think the output tries to be as primitive as possible - here's an intriguing example:

var i:int = 1;
var mc:MovieClip = new MovieClip();

trace(typeof(i)); // number
trace(typeof(mc)); // object

Did a bit of reasearch: typeof can only return of of these six results:

Array -> object
Boolean -> boolean
Function -> function
int -> number
Number -> number
Object -> object
String -> string
uint -> number
XML -> xml
XMLList -> xml

"Evaluates expression and returns a string specifying the expression's data type. The result is limited to six possible string values: boolean, function, number, object, string, and xml. If you apply this operator to an instance of a user-defined class, the result is the string object. The typeof operator is included for backward compatibility. Use the is operator to check type compatibility."


I have found an interesting post about int vs Number: Avoid ints in ActionScript. Given that and that int is also an object: ActionScript Reference what happens is that the debugger will convert int into Number and display its value perhaps just because Number is a broader type and can hold all ints while the other way round is not true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜