Much later than planned I finally got around to checking out AS3.
I was quick to upgrade to AS2 when it came out in Flash MX 2004, and never looked back, so why so late? Well, as usual, because I’m busy. Busy on a PHP project at that, so I haven’t really had the chance. Plus, if I do have to write some AS on the job it’s too big a risk to start learning something new. Pressures demand that I get on with it as I know how. That’s why this Facebook application has it’s main Flash app (Chin Balls) written in AS2. Also, I view the upgrading of a programming language as a one-way process. I didn’t upgrade to PHP5 until I was confident I would never have to write PHP4 again. And with AS3 this is an even bigger deal.
I anticipated that AS3 was going to be stricter, less forgiving, and that I’d have to get used to a few things, but I have to confess to being quite surprised at how different it is. There’s so much material on AS3 available to you that there’s no point me banging on about things you can get better information on else where. However, as an AS2 developer here’s a quick list in no particular order of the things that either surprised or pleased me in my first couple of hours of AS3 writing:
- The MovieClip’s inheritance chain has 5 other classes between itself and the Object class. This abstracts out various types of functionality and means you don’t have to use a fully loaded MovieClip just to display a blob.
- Small, but caught me out – Void must be lower case as a return type, e.g.
function():void{ }
My bad. - Watch out; Ctrl-t only checks syntax.
This is more profound than it sounds. I suspect the reason that AS2 compiles the script and checks all references and types is because that’s the best chance you’ve got of catching an error. AS3 actually has the ability to do this at run time, so don’t think “This script contains no errors” means you’re in the clear! - At last; percentage properties like alpha are now 0-1, instead of 0-100. Another design interface legacy bites the dust. – and say goodbye to underscores in property names too :)
- A new
override
keyword must be used to redefine a parent class method of the same name - MovieClips do not have implicit onEnterFrame, onRelease, or any such handlers invoked by default. You have to explicitly define all event handling via the thoroughly standardized Event mechanism.
- Looking for onLoad? You won’t find it, see above;
- Declaring child clips as member variables in classes was raising conflicts with members of the same name placed physically on the stage. It took me a while to find the publish setting “Automatically declare stage instances”. If you’re used to declaring all your physical members switch this off. If you’re normally lazy, switch it on!
- No more prototype hacking. Not even if it’s 10pm and you really want to go home.