AS3: Deeper down the rabbit hole

Written by cam | April 21st, 2008 | articles

Deeper Down the Rabbit Hole
I have continued to delve deeper and deeper into the world of ActionScript 3.0, and in the process have developed some rather fun components. A site we are working on for one of our clients required a fully featured media player to stream Mp3 files on his site. This became one of the first advanced components I developed using AS3.

Again I stuck with a common feature of passing the component an XML file to read, though in this case I switched it up just a little bit. This time I used a simple PHP script which reads mp3 files from a folder and parses an XML playlist using the files ID3 tags. The Flash file generates the playlist based on this file, making this player a very re-usable component as it can be skinned in a matter of minutes and the only setup required is telling the player where to look for its playlist. This player incorporates some very cool features such as the live spectrum analyzer, sound buffering and scrubbing, volume slider and dynamic playlist.

Also on the list of more advanced components to develop was a horizontal ‘tsunami’ menu. I had developed a tag display system using this technique for the UBC SALA site and I thought it would be an interesting experiment to port the script over to AS3. To my knowledge no one has yet built a tsunami menu using AS3, so this was a fun and challenging build. There are still some bugs to work out in this file, mainly relating to the highlighting of tags, but it is a solid rough example of the tsunami effect in AS3.

Both of these projects have really helped me build my knowledge of the ins and outs of working in AS3, and I have to say that I am still a little on the fence about the whole thing. Overall I really am starting to prefer AS3 to AS2, but there are none the less some things in AS3 which really, really…. really bug me. Firstly, what is up with all the nonsense errors AS3 tends to throw!? I have had to make good friends with Google search to discover the roots of some of these cryptic error messages flash likes to throw now. Fortunately, Curtis Morley has been nice enough to develop an entire site devoted to dispelling the mythical AS3 error codes. This site has become my new best friend as I really just can’t understand why, with all the major improvements in Flash CS3 that they couldn’t work out some better error descriptions, or at least give you the line number… something… anything… would help.

Despite a few hair pulling sessions I am getting more and more comfortable working in AS3 and developing more complicated AS3 components and applications. But there are still some things about AS3 that have left me scratching my head, such as why the onReleaseOutside method dissappeared? This is a really painful function to do without, especially when using draggable objects. I mean seriously, how hard would it have been to add in a MOUSE_UP_OUTSIDE method you could listen for?? In any case I found a suitable work around for this by adding a mouse up listener to the stage, but this still seems like an awkward way to handle a relatively simple event.

Another strange change I have come across is the changes Adobe has made to the startDrag function. In AS2 you were able to pass the function a set of co-ordinates to confine the dragging of an object… which has now been deprecated. I knew that there MUST still be a way to handle this, and it took me a couple hours of digging in the Flash help files to find the solution. In AS3 you must declare a Rectangle variable, and then pass the rectangle into the startDrag function. The rectangle will then confine the dragging of the object. I find that this is actually quite a nice fix, but my problem is with the way that Flash’s own documentation buried this feature in the help files. I guess my real issue with AS3 comes down to documentation: Adobe, why have you done such a piss poor job of documenting all these changes to your proprietary scripting language??? Why must I comb the web for answers to relatively simple problems?? Why must I have to search the web just to find out what your cryptic error messages really mean?

All in all, I have realized that my issue with the new version of Actionscript lies not with the language itself but with Adobe’s documentation of the language. To be honest, I think that Adobe could really have done a better job of documenting all of the changes to the language. This would really have gone a long way to making the new version of the language much more accessible for lower level coders and those of us who were familiar with the nuances of AS2. Had Adobe made more of an effort to make the transition a little smoother I think that we would be seeing many more people getting into the AS3 development environment. I hate to do this, but this new version of Actionscript seems to be suffering from the ‘Vista’ phenomena. Adding complexity to simple tasks, and adding simplicity to complex tasks. This is a trade off which I feel Adobe could have managed much better.

What are your thoughts? Feel free to comment.