I was working to a flex project and I just need to make a cast to a value to int … this it’s simple … and not so.
After few hour later, I have a vision
…
I just try to make a cost from a decimal value to int, and I have noticed that depends on how it’s made … those are the conclusions:
var tmp:int = 57.83 as int // return 0 var tmp:int = 0; tmp = 57.83 as int //return 0 var tmp:int = int(57.83); //retun 57 var tmp:int = 0; tmp = int(57.83); //return 57
When you make a cast to int, ActionScript evaluates the string that you give (ie: 57.83 as int) and if all chars are numbers will return the number as an int, but if you use int method takes the integer from the expression you give (this is similar to math.floor).
If there is something that I missed or it’s not explained properly, please comment.
Popularity: 15%
Tags: ActionScript, int, typecast
This post was written by Stelian Crisan
Views: 863



















I had a similar problem with XML data loaded in and numbers vs strings:
var splashString:String = xml.year.value as String;
Is null / empty.
is okay because it contains non-integer characters.
Fix:
var splashString:String = xml.year.value.toString(); //grr