5 Reasons why you should never go back to AS 2.0
February 1st, 2008
Here at Emak Mafu we’ve been working on project that for one reason or another has to be coded in AS 2.0, which is a real pain seen as I’ve recently made the jump to AS 3. In this past week my screen has seen more yelling than ever, and I thought I’d let you know why.
Debugging
Where on earth are the compile time errors in AS 2? Seriously, if your working with complex/dynamic objects, or using any sort of design patterns then you might as well go home. I would estimate that about 40% of my coding time has been spent sifting through my code looking for things that AS 3 simply would not let you code, which brings us to…
Loosely Typed Objects
So it seems that without the mx library, AS 2 has about 4 classes (ok, maybe slightly more) which makes it really hard to predict the inputs and output of various core components. Worse still it seems that every plug-in and framework under to sun has been built with no extension in mind, at least with AS 3 you’d usually start off by extending the…
EventDispatcher
Thank god for the mx EventDispatcher, I think I would have gone crazy if I had to keep passing references in and out of singletons, where’s the cohesion in that? Its not the best though, and the number of times I’ve tried to dispatch an event from a MovieClip (errh, no Sprites?) or Object without first initializing it with an EventDispatcher, why its like trying to invoke Quicksilver on someone else’s mac, only to find there not using it (its doubly embarrassing if their using a PC). And speaking of Sprites….
CreateEmptyMovieClip()
I hate this, I really, really hate this. Lets say I want to create a MovieClip, and store a reference to that MovieClip. Here we go…
var mc:MovieClip = _scope.createEmptyMovieClip("mc", _scope.getNextHighestDepth());
Do any of you clever communication experts see the redundancy? I have a variable called mc, but I also specify a string name “mc” as well. Why? I don’t know, well I guess I do, its because the stage and variable components of the MovieClip model are not loosely coupled i.e. to create a MovieClip, you have to place it on the stage there is none of this lovely var mySprite:Sprite = new Sprite(); business that we have in AS 3. The most frustrating thing about this is, is that if you are naming clips in a loop, you may inadvertently confuse your variables, which is again all about the debugging. I suppose if you had to sum it up, you could say that its a…
Better Language
Because AS 3 is more like Java, you tend to think in a more OOP way, which in turn makes you think about things a bit differently. Instead of rushing in and hacking together a solution, you tend to think about how you are going to extend and re-use your code. Of course, this is not to say people didn’t do this in AS 2, it just feels more natural in AS 3 and it shows. You can tell when your coding in AS 2 that they haven’t gone the whole-hog. Some features in particular feel like they’ve been tacked on (the MovieClip.beginFill() as opposed to Sprite.graphics.beginFill() for example), creating some kind of mad-max-esque contraption.
I hope that this persuades some of you who are reading this to make the move to AS 3, best thing I ever did (coding wise, I’m not that sad).
March 6th, 2008 at 11:11 pm
Spot on! I swithed to AS3 as soon as lynda.com got on the case and didn’t look back.
Then last week a friend of mine was having trouble getting a button click handler to function. So he sent me the fla to have a look, which I did. It turned out he was using AS 2 and this was his first time coming up against the scope difference that can happen between that inside the onRelease handler function and that of the actual frame he was coding it into. Thats when i realy realised how much i like the AS 3 (ecma) event model.
“This just dosn’t happen in AS 3!” I told him “You need to get with the times.” lol.
I preceeded to introduce him to the wonders of…
var thisObj:Object = this;
He went merrily on his way having learnd a new trick (hack), and i returnd greatfully to my eclipse AS 3 project (mmmm code hinting, refactoring, yum).
Needless to say i agree with everything you said here.