Does actionscript have javascript’s gotchas?

Actionscript is a dialect of ECMAScript and therefore very close to javascript, but it really doesn’t feel it, especially when you’re following the usual advice to use static typing. I was curious if some of javascript’s peculiarities (like these and these) that trip up beginners come up in actionscript, too.

1. Floating point arithmetic - in javascript, 0.02 / 0.1 = 0.19999999999999998.

Actionscript: math is hard! Same result.

2. Semicolon insertion at line feed – in javascript, the following returns undefined instead of ‘aString’, which might seem odd at first glance.

Actionscript: if you add a type to the return value:

you get a compile error. But if you don’t add the return type, you get the same result. You might think that the Flashbuilder IDE would give a warning about unreachable code, but alas, it does not.

3. Attribute syntax can be confusing with arrays - setting an attribute on an array object can look like you’re adding an item to the array.

Actionscript: the same.

4. Setting variable scope – in javascript, ‘var x = y = 1′ will give x a local scope and y a global scope.

Actionscript: gives a compiler error that y is an undefined property.

5. ParseInt function - in javascript, parseInt(“000123″) returns 83.

Actionscript: returns 123! Maybe math isn’t so hard after all.

This entry was posted in flex, software and tagged . Bookmark the permalink.

2 Responses to Does actionscript have javascript’s gotchas?

  1. yifei says:

    parseInt(“000123″) parseInt(“0123″) 83 // octal integer

  2. Thank you, I have just been looking for information approximately this topic for a long time and yours
    is the best I’ve found out till now. However, what about the conclusion? Are you sure concerning the supply?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>