What is the difference between ActionScript 2.0 and ActionScript 3.0

31,945

Solution 1

Besides the library changes, Actionscript 3 is compiled for and run on a completely different virtual machine (AVM2), which was re-written from the ground up. It reportedly executes compiled AS3 code up to 10 times faster than code script compiled for the AVM1 virtual machine.

You should check out this doc for a list of differences between AS2 and AS3 as they can't be explained any better on SO :)

Solution 2

In AS3 you can structure and organise your application a lot more strategically. It's faster, neater and far more recommended than AS2. The main difference is that you can develop flash applications with a much stronger OOP influence than in AS2.

AS3 makes it much easier to utilise third party code such as Greensock's Tweenlite, Papervision 3D and box2d.

In AS2 you would have to use prototype to messily achieve what a class can do for you in AS3. Example:

AS2 prototype:

MovieClip.prototype.flip = function():Void
{
    this._rotation += 180;
}

AS3 class that can be used as a base class for all your MovieClips:

package
{
    import flash.display.MovieClip;

    public class MyMovieClip extends MovieClip
    {
        public function flip():void
        {
            rotation += 180;
        }
    }
}

Though there is more code in creating your own class, you can now extend this class and simply call flip() from within it to run the flip() method. In AS2, you would have to be in the same scope as your MovieClip.prototype.flip() function to access it, which can cause a mess.

Here's the AS2 and AS3 comparison for creating a MovieClip, adding it to the stage and then making use of your flip() function:

AS3:

var mc:MyMovieClip = new MyMovieClip();
mc.flip();

addChild(mc);

AS2::

MovieClip.prototype.flip = function():Void
{
    this._rotation += 180;
}
var mc:MovieClip = attachMovie("your_library_mc", "newname", this.getNextHighestDepth());
mc.flip();
Share:
31,945
Admin
Author by

Admin

Updated on June 02, 2020

Comments

  • Admin
    Admin almost 4 years

    What are the main differences between the versions?

  • fenomas
    fenomas almost 13 years
    And a non-technical addendum: AS2 is the legacy language, AS3 is the current language. New features that get added to the Flash player generally aren't usable from AS2.