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
overridekeyword 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.
Leave a comment