What are the main differences between the versions?
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 :)
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With