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).

3 Responses to ActionScript 3 Makes My Life Easier

  1. Mr. Cantrell, I’m not sure if this is a contact form or not, but I have been going through the Macromedia Flash / JavaScript Integration Kit and trying to figure out how to do the following. Can you help?I am loading a text file in to a TextArea component in Flash 8 Pro and I have set textArea.HTML = True. I want to basically href a line of text to link not to a web page, but to run a loadMovie command. All of the site files are individual swf files for light page weight and quick loading, and with the external text files, I’d like to be able to load the files in to my empty movie clip container. Is this possible? Thanks for your time.

  2. mystrdat says:

    Dear Mr. Cantrell, because of all the unnecessarily deleted or migrated functions that AS2 used in a very easy understandable way, I can now plainly say, that you can shove ActionScript 3 up your ass.

  3. jrm says:

    Well written :)A small note though; the old XMLSockets in AS2 functioned as binary sockets too. If you implemented the onData event and used the sendData function instead of onXMLData and sendXMLData.. well you get it :). The reason I know is because I built a simple multiplayer game using that feature/bug using only a stupid echoserver writen in perl as backend… All in all though I will admit that AS3 makes life so much easier. The added support for classes and object oriented development alone is a killer. And the new improved Event handling helps to build software with loosely coupled classes. At the moment I’m struggling a bit to get a new application to work properly… No reported compilation errors, I do wish there was a stricted compiler out there. Well I guess its back to buisness again.Hmm and all I really wanted to write about was the old XMLSocket… Ahh well brevity was never a strength of mine./jrmP.S.The performance gain in AS3 (up to 10x) is not to be scoffed at either.