ActionScript 3 Makes My Life Easier

Now that I’m back and building Apollo apps, I’m obviously spending a lot of time with ActionScript 3 again. I’ve been using AS3 since there was a compiler capable of compiling it, but during my sabbatical, I wrote primarily Java and ColdFusion code. Now that I’m back, I have the pleasure of rediscovering all the things I love about ActionScript 3, and all the ways it makes my live easier than it was in the AS2 days:

  • Enhanced "for" loops. Being able to use "for..in" and "for each..in" is a huge time saver over the course of several days of programming. Make sure you know when to use which, though.
  • The "as" operator. There are two ways to cast objects in ActionScript. The usual syntax of "SomeObject(someValue)" and the new "as" operator. For some reason, I’ve come to prefer using the "as" operator in many circumstances, I think because I often realize that I need to cast something after I’ve typed it, so using "as" lets me do the cast without having to move my cursor back. It’s also slightly more readable, in my opinion. (It’s a small thing, but when you write enough lines of code, small things add up.)
  • Regular expressions. All I can say about regular expressions is: how did we ever program in ActionScript without them?
  • Sockets. I never felt like ActionScript was blatantly missing a socket object, but now that it’s there, it opens up so many new possibilities (which I’ll be posting about soon).
  • e4x. Once you’ve used e4x to manage XML, you’ll never want to use anything else. I got a heavy dose of e4x early on when I wrote the RSS/Atom library, and I got so used to it that dealing with XML in any other language is a huge bummer now. e4x makes using XML as easy as not using it.

Of course, there are a lot of other things about AS3 that I love . I know they’ve been thoroughly covered in the Flash blogosphere, but I’m having so much fun writing Flex 2 / ActionScript 3 code again that I couldn’t help adding one more post. You can check out several examples of these things in action in the Adobe Labs source code repository browser (which I wrote in PHP, by the way, wishing the entire time that I could write it in AS3).