Actionscript 2 vs Actionscript 3 – A practical comparison.
For alot of budding Flash game developers, our times bring with them a choice: AS3 – To switch or not to switch.
For those who are learning from scratch, the choice is obvious, you should definitely learn AS3 to begin with, AS2 is old hat, archeic, “Grandpa’s Actionscript”. Ok, well it’s probaly not referred to as that last one anyhow. However those, like myself, who “Grew up” on AS2 may feel a fond affection for it’s warm, snuggly,forgiving style. AS2 will let you off with a whole load of corner cutting, if you don’t mind the odd messy segment of code or a slight performance decrease. I currently have three games in the pipes, one of them is AS2, the other two are AS3, and switching between them (I like variation in the projects I’m working on) can be a bit brain frazzling at times, and for what gain? I set out, in a spare half hour, to test the practical benefit of coding in AS3 over AS2, and will let you decide for yourself if you think it’s worth it.
The files attached to this post are the source files I have used for this test. They are both self contained with no external class declarations for ease of distribution. Both are coded to generate 4000 “particles” of a YinYang design consisting of 21 curves (So while not overly complicated, it gives a much fairer comparison to everyday usage than the many Bitmap data particle systems you can find on google that show AS3 as performing 10-15 times faster than AS2)
Once 4000 YinYang particles have been generated, the amount of time it took to do this is traced in the output box in milliseconds. I have chosen the method of controlling the particles by a set of three Arrays for 2 reasons. 1. It allows me to keep the actual code used 99 percent Identical in both the AS2 and AS3 versions and 2. Array Manipulation is very heavy on the performance of Flash. So with this experiment we shall see the results of a PRACTICAL (i.e. similar to conditions one would use while actually making a game) comparison between AS2 performance and AS3 performance. Not only is there heavy strain on loops to account for code processing, but an awful lot of screen redrawing at a practical 25fps.
Here are my own personal results (which may differ from yours depending on what machine/plugin you use to play the file)
Intel Core Duo 1.66 GHZ
2GB DDR2 RAM
Geforce Go 7600.
Actionscript 2 Average over 10 trials to generate 4000 particles: 18890 Milliseconds
Actionscript 3 Average over 10 trials to generate 4000 particles: 8344 Milliseconds
The conclusion is, as expected, the AS3 version was faster than the AS2 version, but only just over twice as fast. This indeed does present a necessity to upgrade to keep up with the ever increasing complexity of current Flash games, and the benefits of a few new features, but, in my opinion, a practical speed advantage of just over 2 is far from the promise of Adobes virtual machine speed revolution. It seems the promised 10 times increase in performance was only meant for those entertaining blogs which showcase the authors experiments in Flash, which, valid as they are, do not apply to practical Flash Game Development.
So do I recommend the upgrade to AS3? It depends. If you are still using a version of Flash which doesn’t support it, then I’d say for now that there truly is no rush to throw money at Adobe for an upgrade to AS3 (via a Flash CS3 purchase) However, if you’re dragging your feet for comforts sake, throw yourself in head first and try something new. Just keep in mind, will your game be running faster at the compromise of cut features due to inexperience in the vastly different AS3? If so, it bears well to remember, that a faster codebase does not equate to a better game.
Thanks for reading this hefty post, I’m sorry if you felt it was rather drawn out, but I think it’s an issue which has only been really addressed by the Flash Experiment community, not the Game Development Community.