« RSL further details
» Two Simple Ways to Invert the Colors of an Image

ActionScript

Cast to int issue

Stelian Crisan | 11.01.08 | 1 Comment

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.

Share and Enjoy:
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • description
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride




Tags: , ,

This post was written by Stelian Crisan

Views: 1321

related

1 Comment

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

:

:


« RSL further details
» Two Simple Ways to Invert the Colors of an Image