a few thoughts on ActionScript 3
I just completed a "Don't Forget the Lyrics"-style program for a friend.
Basically, it had the following specs:
- load audio files (.mp3).
- load video files (.flv).
- load text files (.lrc).
- display lyrics/subtitles synced with media files.
There were also other requirements, such as having one-time-only songs, a 3-tier hierarchy, media-subtitle delay/offsets, and other nitty-gritty.
When I was first briefed about the specs, Flash came to mind immediately as the ideal platform for implementation. It has good media-handling, comes with a convenient video player (with the Flash IDE, that it), and besides, I was familiar with it.
Used to, that is. It's been a looong time since I last touched Flash/ActionScript - almost 4 years. Many things have changed since my ActionScript 2 days when Flash MX was around. I messed a lot with AS2 then, but I gradually lost touch and the launch of AS3 was lost on me.
So I picked up Adobe's Learning ActionScript 3.0. Although I felt that it was geared towards non-programmers, it was concise and I managed to pick up the important changes from AS2 to AS3. Within 2 days, I was hitting the still-excellent FlashDevelop IDE, but without the mtasc compiler - instead, Adobe's own, provided with the Flex 4 SDK.
Some of the more interesting AS3 changes:
-
E4X - this is a really really cool way of parsing XML. In those days, one would have to target elements with
nodeValue
andchildren[0].attributes['foo']
, which was ugly. Now, you can just toparent.child
orparent.@attr
. But this leads to some typing ambiguity. - Regular expressions. 'Nuff said.
-
Reworked OOP - no more
prototype
magic, and there's very little need to usethis
- class and instance methods/variables can be referenced without it. -
'Magic' closures - one used to have to use mx.utils.Delegate to preserve scope. Now, the compiler/interpreter is smart enough to do that. You still have to create a reference to
this
(eg.var self:Foo = this;
) if you need to access the current object, though. -
new methods on Array - I'm a big fan of Python's list comprehensions and iterators. The new methods
map()
andfilter()
allow one to get this functionality - to some extent, at least.
Updated 2013-08-07: fixed mtasc link