User Guide

Working with display objects 167
Working with display objects
Now that you understand the basic concepts of the Stage, display objects, display object
containers, and the display list, this section provides you with some more specific information
about working with display objects in ActionScript 3.0.
Properties and methods of the DisplayObject class
All display objects are subclasses of the DisplayObject class, and as such they inherit the
properties and methods of the DisplayObject class. The properties inherited are basic
properties that apply to all display objects. For example, each display object has an
x property
and a
y property that specifies the objects position in its display object container.
There is no constructor function for the DisplayObject class. You must create another type of
object (an object that is a subclass of the DisplayObject type), such as a Sprite, to instantiate
an object with the
new constructor. Also, if you want to create a custom display object class,
you must create a subclass of one of the display object subclasses that has a usable constructor
function (such as the Shape class or the Sprite class).
Adding display objects to the display list
When you instantiate a display object, it will not appear onscreen (on the Stage) until you add
the display object instance to a display object container that is on the display list. For example,
in the following code, the
myText TextField object would not be visible if you omitted the last
line of code. In the last line of code, the
this keyword must refer to a display object container
that is already added to the display list.
import flash.display.*;
import flash.text.TextField;
var myText:TextField = new TextField();
myText.text = "Buenos dias.";
this.addChild(myText);
When you add any visual element to the Stage, that element becomes a child of the Stage
object. The first SWF file loaded in an application (for example, the one that you embed in an
HTML page) is automatically added as a child of the Stage. It can be an object of any type
that extends the Sprite class.