From AS2 to AS3: The Migration


Written By MrSun at 12:47 pm - Saturday, July 26th, 2008
Categories: AS2, AS3, Flash

With the release of Adobe’s Flash CS3 about a year ago came a newer version of Actionscript, AS3. Even though it has been quite some time since that release, many have not begun to use the newer version. Though the migration is not required, I find it very necessary. The differences in these two languages may make AS3 harder to learn, but that does not outweigh the benefits of switching.

  • The main difference between AS2 and AS3 is that AS3 almost enforces object-oriented programming by not allowing code to be placed onto movieclips. If you don’t know what object-oriented programming is, then you should refer to this article to get an idea
  • Many of the object properties, including _x, _y, _parent, _visible, etc, do not require an underscore before them, they are simply x, y, parent, visible, etc
  • You need to type MovieClip(root) instead of root to access the main timeline. The same goes for parent.
  • In order to have enterFrame events, you must add listeners to the object:

    mc.addEventListener(Event.ENTER_FRAME, enterFrameFunction);

    The listener points to a function which is run whenever the listener is activated. In this case, that happens every time the movieclip is in frame.

    function enterFrameFunction(event:Event):void{

    //actions go here

    }

  • Variables also require new syntax. In AS2, all you had to do was type the variable name and it’s value, like so:

    myVar = 1;

    In AS3, you now have to declare the variable before defining it’s value:

    var myVar = 1;

    This was optional in AS2, but now it is enforced in AS3. This helps because it speeds up the code, making your flash application faster. To increase your code’s speed even more, you can declare the datatype of the variable:

    var myVar:int = 1;

    The datatype is the word after the colon (int means that the variable must be an integer)

Those are only a few of the many differences between these two versatile languages. Here are some links that will also help in your migration:

And some books:

«
»