A foray into ActionScript

2009 August 13
by monzee

A couple of months ago, I was asked to write a desktop program that would interface with a GSM/VoIP gateway. The SMS web interface built into the box was lacking, so the client asked me to write a custom program with more features and a more intuitive interface.

I chose to use the Flex framework and Adobe AIR to deploy the program. Overall, it was an okay experience, although there are some parts that drove me nuts:

What I liked
  • Javascript-like syntax

    ActionScript is an implementation of ECMAScript, just like Javascript. Although coming from the same specs, programming in AS feels much closer to PHP than JS because of its classical object model complete with privates, statics, abstracts and everything else. This combined with the familiar C-like constructs allowed me to start from zero AS/Flex knowledge to a complete working program in a little over two weeks.

  • Accessor methods

    I pretty much use only public properties in my classes, but if there are times when I need to define custom logic during assignment or access (e.g. lazy connection to the socket), I could just define a get or set method for those properties. The best part, I don’t have to change the statements I already have written to use these accessors! They are automatically called whenever the property is accessed directly. It’s doable in PHP with __get and __set but you’ll end up with a giant switch statement in there and they likely won’t be discoverable by any IDE.

  • MXML layouts

    Laying out GUI widgets using HBoxes, VBoxes, Panels and other containers is a hundred times easier than HTML/CSS. Why can’t CSS be this simple? The default style looks good too, so I didn’t have to worry about changing the appearance and I was able to concentrate on the logic. Creating an interface through MXML reminded me a lot of Sonique2 (MML/MantisScript) and Winamp3 (XML/Maki) skinning, which were the main reasons I got into web/interface design and eventually PHP development.

What I wasn’t too crazy about
  • Asynchronicity, events and listeners

    I like its side-effect of maintaining the responsiveness of the application while doing a somewhat expensive task, but debugging is hell! It’s very difficult to follow the program flow. I also don’t think exceptions thrown by handlers are catchable, so I had to trigger error events and register even more handlers inside my handlers. And also made sure that the handlers are unregistered after they fired. The worst was when I had to send a sequence of commands to the socket connection. The listener was so deeply-nested and confusing that I just gave up error-handling altogether and just threw the commands in a queue which will be sent one-by-one regardless of the reply from the gateway.

  • Online resources are centered so much on FlexBuilder

    I’m sure it’s possible to develop Flex programs with just a text editor and the compiler bundled with Flex, but I wasn’t able to find any information on how to do so. Most tutorials just assume that you are using Adobe’s (not free) IDE. I wasn’t able to follow along even the simplest tutorials until I’ve found FlashDevelop. It is a good free IDE, but I wished it had a drag-and-drop GUI builder. That would have expedited my learning during the first couple of days.

Confusing as they are, I still think events are a good thing. I think that model would work in an MVC framework. I’m thinking of removing the dependency on the ZF MVC stack in my snap project to make it faster. If I ever do, the front controller would likely be a static event dispatcher object and the other components register themselves as listeners. I just wish I had more time to work on this.

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS