The
dawn of Flash CS3 means the ability to use actionsript 3.0. No
longer can you only access the new powers of actionscript with just flex
2. In this tutorial, I am going to discuss one of the main diffrences
between Actionscript 3.0 and Actionscript 2.0/1.0, which is the display list, DisplayObjects, and DisplayObjectContainers.First, lets discuss the display list. The display list manages all
objects that can be displayed in the flash player and it is going to effect the way you
add objects to it. Below is an example of how you created a new
object (in this case, a MovieClip) and added it to the stage in
AS2.0/1.0, and how it is now done in AS 3.0.
actionscript
1.0/2.0
//main timeline: frame 1
this.createEmptyMovieClip("my_mc", this.getNextHighestDepth());
trace(my_mc);
//outputs: _level0.my_mc
actionscript 3.0
//main timeline: frame 1
var myMovieClip:MovieClip = new MovieClip();
this.addChild(myMovieClip);
trace(myMovieClip);
//outputs: [object MovieClip]
The
first thing you'll notice is that in AS 3.0, you can now create
any object by using the “new” statement. This includes Buttons and TextFields as well. The next thing you'll notice is that
you no longer have to give a depth to an object, this is because
“depth” no longer exsists in actionscript. Instead when you
create an object in AS 3.0, it is created, but not automatily added
to the stage. The display list manages all visible objects on the stage, anything that is not
apart of the display list is concidered invisible. In order to add
the object to the stage, we must use the addChild method of any
DisplayObjectContainer (the main timeline or “_root” is a
DisplayObjectContainer, I'll discuss this shortly). You may have aslo
noticed that in AS 3.0, we did not give our movieClip object an
instance name. In oder to do this, we need to use the MovieClip.name
property and set the name. So for our above example:
myMovieClip.name = "my_mc";
If your are working mainly with actionscript though, you may not need to set
the name property, since when you create the object you give it a
variable name which you would use to refrence the object instead.
Ok, let
us move on to DisplayObjects and DisplayObjectContainers