The great AS3/AS2 debate: Is it slower to work with AS3 than AS2? My take: A bit

Mike Chambers, Principal Product Manager for developer relations from Adobe, has been pinging the Flash community about whether AS2 based development is faster than AS3 for Flash projects. Having spent a long time in both languages, I thought I would post my 2 cents on this blog. So my answer is: Yes. Of course I’ll qualify my statement by saying that 1) There are a lot of capabilities in Flash 9+ that are amazing but I want to disconnect the language (pure syntax) from what it enables and 2) This post assumes you are as comfortable with AS3 as AS2. I am not factoring in the learning curve for a new language, which happens anytime there is a drastic change.

AS3 can use some help. Let me list out some reasons why I say that:

  1. Loading XML is a complete pain
  2. Calling an external URL is AS2 was simple (although having to use delegate because of the lack of proper closures was retarded). The code was something like this:
    var xml:XML = new XML()
    xml.ignoreWhite = true;
    xml.onLoad = function(success){

    Very readable, plus all errors were available in one check. Lets compare that to AS3:

    XML.ignoreWhite = true;
    var urlLoader:URLLoader = new URLLoader()
    var urlRequest = new URLRequest(‘doc.xml’)
    var urlVariables = new URLVariables() = bar = urlVariables
    loader.addEventListener(IOErrorEvent.IOError, onError)
    loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
    loader.addEventListener(Event.COMPLETE, onComplete)


    How verbose is that? I am still trying to figure out why every request needs a URLRequest object, seems unnecessary. just calling urlLoader.load(“data.xml”) could automatically create a URLRequest object, if you ever want to examine a request post it being called. Another huge problem is most developers I know dont actually add the error event listeners, just cause adding it is so tiresome. So when an error occurs later, they are usually clueless to what happened (was it a code bug or did some http call out just did not work?).

    The URLRequest param for navigateToURL seems another one of those requirements that seem unnecessary.

  3. Whoops, forgot my addChild
  4. I think this is where I have lost countless hours, I would create a sprite, and set its properties, but forget to add it to the stage…and then spend too much time to figure out what did I do wrong. The only way to create a new UI element in AS2 was by referencing an already added MovieClip (remember my_mc.createEmptyMovieClip() ?). I would love to have a createAndAdd function in DisplayObjects that becomes the default way of creating new Sprites.

  5. Dynamic drawing: The graphics object
  6. Drawing in AS2 was simpler: MovieClip.lineTo(….). In AS3 it has to be on the graphics context of the DisplayObject ( ), but why? There isnt any other context to draw on, and the graphics context isnt swappable, so why do I have to type that in?

  7. No numeric depths
  8. In AS2, you could set explicit depth numbers to elements and reorder elements under those depths. So for example, if you were writing a button control, you could set the label field up on depth 1000 and keep swapping out the children under it. In AS2, you have to track where in the display tree your element is.

  9. useHandCursor vs ButtonMode + useHandCursor
  10. I dont know what buttonMode does besides actually allow me to useHandCursor property, which I have to set anyway

  11. No onReleaseOutside
  12. This one also is weird. The way we now have to do an onReleaseOutside is via listening to a stage click event. But wait, you may not be on stage yet, so you need to check : if(stage), and also write an event listener to the addedToStage event. Verbose.

  13. addEventListener vs. onRelease
  14. onRelease (and similar “on…” functions) is not a bad default hook to have. Considering how often we write these functions, having a quick shortcut to the action was nice. Not that I am saying the event model is bad, but I end up writing a lot of addEventListeners and removeEventListener throughout the code.

I think overall, when I look at an AS3 file, it just seems longer than AS2 code used to. I think everything needs to be very explicitly set in AS3 with no smart defaults. Maybe that’ll change in AS4 now that we no longer care for the ECMA spec ;). There are a lot of improvements in AS3 as well though, like actually having private and protected namespaces, but I am only listing out my pet peeves here hoping Mike takes note :). Flash is an amazing platform, and I love what it enables me to do.

The great AS3/AS2 debate: Is it slower to work with AS3 than AS2? My take: A bit

7 thoughts on “The great AS3/AS2 debate: Is it slower to work with AS3 than AS2? My take: A bit

  1. Well, I’ll just say that all of this removed by one very very simple fact. If you use flex builder to test your code, your errors come up as you save, not as you launch. You will save 1000% right there in time.

    You will find in time that you will work faster, as you start building yourself libraries.

    Yes it is more typing, but faster dev. Try adding debug points in AS2. You end up creating 4000 trace statements on every single item. And parsing XML, dear lord, I don’t know how you could even mention that when parsing XML before consisted of:

    loop; if type == 1 || type == 3; loop; if type == 1 || type == 3; loop; loop; if type == 1 || type == 3; loop; if type == 1 || type == 3; loop; loop; if type == 1 || type == 3; loop; if type == 1 || type == 3; loop;

    consistency is faster over the long run. for shiz.


  2. I definitely agree with you about a lot of these, but onReleaseOutside behaviour is still possible. You have to listen for Event.MOUSE_LEAVE on the stage. It’s extremely frustrating that it’s not a MouseEvent, because your MOUSE_UP handler for dragging has to take an Event, which often trips me up. Also, as you say, you have to listen for Event.ADDED_TO_STAGE in order to add a listener to the stage. Anyway, the functionality is there, even though many Flash apps suffer from not responding to it.


  3. George K says:

    Isn’t ignore white redundant in AS3? I was under the impression that it was automatic?

    Also, is AS2 automatically handling the error reporting? You have 2 lines dedicated to error event listeners but there doesn’t seem to be anything comprable in the AS2 code.

    Also, is it necessary to create the URLVariables? Is it not possible to simply append to the URL the same way you did in the AS2 example?


  4. @Daniel
    True, using Flex Builder is a huge time save, but thats a tooling feature not a language one. What if you are not using Flex Builder but simple TextMate (I do know people who do, thats the joy of having an open source compiler). Point is the extra typing should be gotten rid of.

    Both examples should be showing the same functionality. The AS2 version has an onLoad with a success param that is either true or false. The AS3 has to have 3 listeners explicitly added.

    @George K
    You might be right on the ignoreWhite. In AS2 I have the onLoad with a success param that is a boolean. I think its more for when you use HTTP POST. Not sure if AS2 had POST.


  5. I personally think writing in AS3 is faster now. That is because I have been writing in it for some time now. When I was first converting from 2 to 3, I thought the opposite. I do think AS3 wins!!!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s