| Package | flash.display |
| Class | public class DisplayObjectContainer |
| Inheritance | DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object |
| Subclasses | Loader, Sprite, Stage |
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
DisplayObject is an abstract base class; therefore, you cannot call DisplayObject directly. Invoking
new DisplayObject() throws an ArgumentError exception.
new DisplayObjectContainer() constructor
throws an ArgumentError exception.
For more information, see the "Display Programming" chapter of the Programming ActionScript 3.0 book.
See also
| Property | Defined By | ||
|---|---|---|---|
![]() | accessibilityProperties : AccessibilityProperties
The current accessibility options for this display object.
| DisplayObject | |
![]() | alpha : Number
Indicates the alpha transparency value of the object specified.
| DisplayObject | |
![]() | blendMode : String
A value from the BlendMode class that specifies which blend mode to use.
| DisplayObject | |
![]() | cacheAsBitmap : Boolean
If set to true, Flash Player or Adobe AIR caches an internal bitmap representation of the
display object.
| DisplayObject | |
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
![]() | contextMenu : NativeMenu
Specifies the context menu associated with this object.
| InteractiveObject | |
![]() | doubleClickEnabled : Boolean
Specifies whether the object receives doubleClick events.
| InteractiveObject | |
![]() | filters : Array
An indexed array that contains each filter object currently associated with the display object.
| DisplayObject | |
![]() | focusRect : Object
Specifies whether this object displays a focus rectangle.
| InteractiveObject | |
![]() | height : Number
Indicates the height of the display object, in pixels.
| DisplayObject | |
![]() | loaderInfo : LoaderInfo
[read-only]
Returns a LoaderInfo object containing information about loading the file
to which this display object belongs.
| DisplayObject | |
![]() | mask : DisplayObject
The calling display object is masked by the specified mask object.
| DisplayObject | |
| mouseChildren : Boolean
Determines whether or not the children of the object are mouse enabled.
| DisplayObjectContainer | ||
![]() | mouseEnabled : Boolean
Specifies whether this object receives mouse messages.
| InteractiveObject | |
![]() | mouseX : Number
[read-only]
Indicates the x coordinate of the mouse position, in pixels.
| DisplayObject | |
![]() | mouseY : Number
[read-only]
Indicates the y coordinate of the mouse position, in pixels.
| DisplayObject | |
![]() | name : String
Indicates the instance name of the DisplayObject.
| DisplayObject | |
| numChildren : int
[read-only]
Returns the number of children of this object.
| DisplayObjectContainer | ||
![]() | opaqueBackground : Object
Specifies whether the display object is opaque with a certain background color.
| DisplayObject | |
![]() | parent : DisplayObjectContainer
[read-only]
Indicates the DisplayObjectContainer object that contains this display object.
| DisplayObject | |
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
![]() | root : DisplayObject
[read-only]
For a display object in a loaded SWF file, the root property is the
top-most display object in the portion of the display list's tree structure represented by that SWF file.
| DisplayObject | |
![]() | rotation : Number
Indicates the rotation of the DisplayObject instance, in degrees, from its original orientation.
| DisplayObject | |
![]() | scale9Grid : Rectangle
The current scaling grid that is in effect.
| DisplayObject | |
![]() | scaleX : Number
Indicates the horizontal scale (percentage) of the object as applied from the registration point.
| DisplayObject | |
![]() | scaleY : Number
Indicates the vertical scale (percentage) of an object as applied from the registration point of the object.
| DisplayObject | |
![]() | scrollRect : Rectangle
The scroll rectangle bounds of the display object.
| DisplayObject | |
![]() | stage : Stage
[read-only]
The Stage of the display object.
| DisplayObject | |
| tabChildren : Boolean
Determines whether the children of the object are tab enabled.
| DisplayObjectContainer | ||
![]() | tabEnabled : Boolean
Specifies whether this object is in the tab order.
| InteractiveObject | |
![]() | tabIndex : int
Specifies the tab ordering of objects in a SWF file.
| InteractiveObject | |
| textSnapshot : TextSnapshot
[read-only]
Returns a TextSnapshot object for this DisplayObjectContainer instance.
| DisplayObjectContainer | ||
![]() | transform : Transform
An object with properties pertaining to a display object's matrix, color transform, and pixel bounds.
| DisplayObject | |
![]() | visible : Boolean
Whether or not the display object is visible.
| DisplayObject | |
![]() | width : Number
Indicates the width of the display object, in pixels.
| DisplayObject | |
![]() | x : Number
Indicates the x coordinate of the DisplayObject instance relative to the local coordinates of
the parent DisplayObjectContainer.
| DisplayObject | |
![]() | y : Number
Indicates the y coordinate of the DisplayObject instance relative to the local coordinates of
the parent DisplayObjectContainer.
| DisplayObject | |
| Method | Defined By | ||
|---|---|---|---|
|
Calling the new DisplayObjectContainer() constructor throws an
ArgumentError exception.
| DisplayObjectContainer | ||
|
Adds a child DisplayObject instance to this DisplayObjectContainer instance.
| DisplayObjectContainer | ||
|
Adds a child DisplayObject instance to this DisplayObjectContainer
instance.
| DisplayObjectContainer | ||
![]() |
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event.
| EventDispatcher | |
|
Indicates whether the security restrictions
would cause any display objects to be omitted from the list returned by calling
the DisplayObjectContainer.getObjectsUnderPoint() method
with the specified point point.
| DisplayObjectContainer | ||
|
Determines whether the specified display object is a child of the DisplayObjectContainer instance or
the instance itself.
| DisplayObjectContainer | ||
![]() |
Dispatches an event into the event flow.
| EventDispatcher | |
![]() |
Returns a rectangle that defines the area of the display object relative to the coordinate system
of the targetCoordinateSpace object.
| DisplayObject | |
|
Returns the child display object instance that exists at the specified index.
| DisplayObjectContainer | ||
|
Returns the child display object that exists with the specified name.
| DisplayObjectContainer | ||
|
Returns the index position of a child DisplayObject instance.
| DisplayObjectContainer | ||
|
Returns an array of objects that lie under the specified point and are children
(or grandchildren, and so on) of this DisplayObjectContainer instance.
| DisplayObjectContainer | ||
![]() |
Returns a rectangle that defines the boundary of the display object,
based on the coordinate system defined by the targetCoordinateSpace
parameter, excluding any strokes on shapes.
| DisplayObject | |
![]() |
Converts the point object from the Stage (global) coordinates
to the display object's (local) coordinates.
| DisplayObject | |
![]() |
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event.
| EventDispatcher | |
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Evaluates the display object to see if it overlaps or intersects with the
obj display object.
| DisplayObject | |
![]() |
Evaluates the display object to see if it overlaps or intersects with the
point specified by the x and y parameters.
| DisplayObject | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Converts the point object from the display object's (local) coordinates to the
Stage (global) coordinates.
| DisplayObject | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
|
Removes the specified child DisplayObject instance from the child list of the DisplayObjectContainer instance.
| DisplayObjectContainer | ||
|
Removes a child DisplayObject from the specified index position in the child list of
the DisplayObjectContainer.
| DisplayObjectContainer | ||
![]() |
Removes a listener from the EventDispatcher object.
| EventDispatcher | |
|
Changes the position of an existing child in the display object container.
| DisplayObjectContainer | ||
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
|
Swaps the z-order (front-to-back order) of the two specified child objects.
| DisplayObjectContainer | ||
|
Swaps the z-order (front-to-back order) of the child objects at the two specified index positions in the
child list.
| DisplayObjectContainer | ||
![]() |
Returns the string representation of the specified object.
| Object | |
![]() |
Returns the primitive value of the specified object.
| Object | |
![]() |
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type.
| EventDispatcher | |
| mouseChildren | property |
mouseChildren:Boolean [read-write]
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Determines whether or not the children of the object are mouse enabled.
If an object is mouse enabled, a user can interact with it by using a mouse. The default is true.
This property is useful when you create a button with an instance of the Sprite class
(instead of using the SimpleButton class). When you use a Sprite instance to create a button,
you can choose to decorate the button by using the addChild() method to add additional
Sprite instances. This process can cause unexpected behavior with mouse events because
the Sprite instances you add as children can become the target object of a mouse event
when you expect the parent instance to be the target object. To ensure that the parent
instance serves as the target objects for mouse events, you can set the
mouseChildren property of the parent instance to false.
No event is dispatched by setting this property. You must use the
addEventListener() method to create interactive functionality.
public function get mouseChildren():Boolean
public function set mouseChildren(value:Boolean):void
See also
container and shows that when you set its mouseChildren property to
false, the target of a mouseClick event is the container
object, not any one of its child objects:
import flash.display.Sprite;
import flash.events.MouseEvent;
var container:Sprite = new Sprite();
container.name = "container";
addChild(container);
var circle:Sprite = new Sprite();
circle.name = "circle";
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(40, 40, 40);
container.addChild(circle);
container.mouseChildren = false;
container.addEventListener(MouseEvent.CLICK, clicked);
function clicked(event:MouseEvent):void {
trace(event.target.name); // container
}
| numChildren | property |
numChildren:int [read-only]
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Returns the number of children of this object.
public function get numChildren():int
See also
container1 and
container2. A Sprite is a type of display object container. The example calls the
addChild() method to set up the display hierarchy: container1 is a child of
container2, and two other display objects, circle1 and circle2,
are children of container1. The calls to the trace() method show the number
of children of each object. Note that grandchildren are not included in the numChildren count:import flash.display.Sprite; var container1:Sprite = new Sprite(); var container2:Sprite = new Sprite(); var circle1:Sprite = new Sprite(); circle1.graphics.beginFill(0xFFCC00); circle1.graphics.drawCircle(40, 40, 40); var circle2:Sprite = new Sprite(); circle2.graphics.beginFill(0x00CCFF); circle2.graphics.drawCircle(80, 40, 40); container2.addChild(container1); container1.addChild(circle1); container1.addChild(circle2); trace(container1.numChildren); // 2 trace(container2.numChildren); // 1 trace(circle1.numChildren); // 0 trace(circle2.numChildren); // 0
| tabChildren | property |
tabChildren:Boolean [read-write]
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Determines whether the children of the object are tab enabled. Enables or disables tabbing for the
children of the object. The default is true.
public function get tabChildren():Boolean
public function set tabChildren(value:Boolean):void
IllegalOperationError — Calling this property of the Stage object
throws an exception. The Stage object does not implement this property.
|
container1 display object container and
adds two display objects, circle1 and circle2,
to its child list. The example sets tabChildren to false for the children so it can
manage its own tab order using tabIndex:import flash.display.Sprite; var container:Sprite = new Sprite(); container.tabChildren = false; var circle1:Sprite = new Sprite(); circle1.graphics.beginFill(0xFFCC00); circle1.graphics.drawCircle(40, 40, 40); circle1.tabIndex = 1; var circle2:Sprite = new Sprite(); circle2.graphics.beginFill(0x00CCFF); circle2.graphics.drawCircle(120, 40, 40); circle2.tabIndex = 0; container.addChild(circle1); container.addChild(circle2);
| textSnapshot | property |
textSnapshot:TextSnapshot [read-only]
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Returns a TextSnapshot object for this DisplayObjectContainer instance.
public function get textSnapshot():TextSnapshot
See also
trace(this.textSnapshot.getText(0, this.textSnapshot.charCount));
| DisplayObjectContainer | () | Constructor |
public function DisplayObjectContainer()
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Calling the new DisplayObjectContainer() constructor throws an
ArgumentError exception. You can, however, call constructors for
the following subclasses of DisplayObjectContainer:
new Loader()new Sprite()new MovieClip()| addChild | () | method |
public function addChild(child:DisplayObject):DisplayObject
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Adds a child DisplayObject instance to this DisplayObjectContainer instance. The child is added
to the front (top) of all other children in this DisplayObjectContainer instance. (To add a child to a
specific index position, use the addChildAt() method.)
If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.
Parameters
child:DisplayObject — The DisplayObject instance to add as a child of this DisplayObjectContainer instance.
|
DisplayObject — The DisplayObject instance that you pass in the
child parameter.
|
added: — Dispatched when a display object is added to the display list. |
ArgumentError — Throws if the child is the same as the parent. Also throws if
the caller is a child (or grandchild etc.) of the child being added.
|
See also
container1 and
container2. A Sprite is a type of display object container. The example calls the
addChild() method to set up the display hierarchy: container1 is a child of
container2, and two other display objects, circle1 and circle2,
are children of container1. The calls to the trace() method show the number
of children of each object. Note that grandchildren are not included in the numChildren count:import flash.display.Sprite; var container1:Sprite = new Sprite(); var container2:Sprite = new Sprite(); var circle1:Sprite = new Sprite(); circle1.graphics.beginFill(0xFFCC00); circle1.graphics.drawCircle(40, 40, 40); var circle2:Sprite = new Sprite(); circle2.graphics.beginFill(0x00CCFF); circle2.graphics.drawCircle(80, 40, 40); container2.addChild(container1); container1.addChild(circle1); container1.addChild(circle2); trace(container1.numChildren); // 2 trace(container2.numChildren); // 1 trace(circle1.numChildren); // 0 trace(circle2.numChildren); // 0
| addChildAt | () | method |
public function addChildAt(child:DisplayObject, index:int):DisplayObject
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Adds a child DisplayObject instance to this DisplayObjectContainer instance. The child is added at the index position specified. An index of 0 represents the back (bottom) of the display list for this DisplayObjectContainer object.
For example, the following example shows three display objects, labeled a, b, and c, at index positions 0, 2, and 1, respectively:
If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.
Parameters
child:DisplayObject — The DisplayObject instance to add as a child of this
DisplayObjectContainer instance.
|
|
index:int — The index position to which the child is added. If you specify a
currently occupied index position, the child object that exists at that position and all
higher positions are moved up one position in the child list.
|
DisplayObject — The DisplayObject instance that you pass in the
child parameter.
|
added: — Dispatched when a display object is added to the display list. |
RangeError — Throws if the index position does not exist in the child list.
|
|
ArgumentError — Throws if the child is the same as the parent. Also throws if
the caller is a child (or grandchild etc.) of the child being added.
|
See also
container display object container and
adds a display objects circle1 to its display list. Then, by calling
container.addChildAt(circle2, 0), it adds the circle2 object to index position
zero (the back), and moves the circle1 object to index position 1:import flash.display.Sprite; var container:Sprite = new Sprite(); var circle1:Sprite = new Sprite(); var circle2:Sprite = new Sprite(); container.addChild(circle1); container.addChildAt(circle2, 0); trace(container.getChildAt(0) == circle2); // true trace(container.getChildAt(1) == circle1); // true
| areInaccessibleObjectsUnderPoint | () | method |
public function areInaccessibleObjectsUnderPoint(point:Point):Boolean
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Indicates whether the security restrictions
would cause any display objects to be omitted from the list returned by calling
the DisplayObjectContainer.getObjectsUnderPoint() method
with the specified point point. By default, content from one domain cannot
access objects from another domain unless they are permitted to do so with a call to the
Security.allowDomain() method.
For more information, see the following:
The point parameter is in the coordinate space of the Stage,
which may differ from the coordinate space of the display object container (unless the
display object container is the Stage). You can use the globalToLocal() and
the localToGlobal() methods to convert points between these coordinate
spaces.
Parameters
point:Point — The point under which to look.
|
Boolean —
true if the point contains child display objects with security restrictions.
|
See also
container.
The next block of code uses a Loader object to load a JPEG file named "test.jpg" from a remote file server.
Note that the checkPolicyFile property of the LoaderContext object used as a parameter in the
load() method is set to false. Once the file is loaded, the code calls
the loaded() method, which in turn calls container.areInaccessibleObjectsUnderPoint(),
which returns a value of true because the loaded content is assumed to be from an
inaccessible domain:
import flash.display.Sprite;
import flash.display.Loader;
import flash.system.LoaderContext;
import flash.net.URLRequest;
import flash.events.Event;
import flash.geom.Point;
var container:Sprite = new Sprite();
var urlReq:URLRequest = new URLRequest("http://localhost/RemoteFile.swf");
var ldr:Loader = new Loader();
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = false;
ldr.load(urlReq, context);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, urlNotFound);
function loaded(event:Event):void {
var pt:Point = new Point(1, 1);
trace(container.areInaccessibleObjectsUnderPoint(pt)); // true
}
function urlNotFound(event:Event):void {
trace("The URL was not found.");
}| contains | () | method |
public function contains(child:DisplayObject):Boolean
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Determines whether the specified display object is a child of the DisplayObjectContainer instance or
the instance itself.
The search includes the entire display list including this DisplayObjectContainer instance. Grandchildren,
great-grandchildren, and so on each return true.
Parameters
child:DisplayObject — The child object to test.
|
Boolean —
true if the child object is a child of the DisplayObjectContainer
or the container itself; otherwise false.
|
contains() method:import flash.display.Sprite; var sprite1:Sprite = new Sprite(); var sprite2:Sprite = new Sprite(); var sprite3:Sprite = new Sprite(); var sprite4:Sprite = new Sprite(); sprite1.addChild(sprite2); sprite2.addChild(sprite3); trace(sprite1.contains(sprite1)); // true trace(sprite1.contains(sprite2)); // true trace(sprite1.contains(sprite3)); // true trace(sprite1.contains(sprite4)); // false
| getChildAt | () | method |
public function getChildAt(index:int):DisplayObject
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Returns the child display object instance that exists at the specified index.
Parameters
index:int — The index position of the child object.
|
DisplayObject — The child display object at the specified index position.
|
RangeError — Throws if the index does not exist in the child list.
|
|
SecurityError — This child display object belongs to a sandbox
to which you do not have access. You can avoid this situation by having
the child movie call Security.allowDomain().
|
See also
container
and then adds a three display objects to the child list of the container object. The calls to the
getChildAt() method then reveal the positions of the child objects:import flash.display.Sprite; var container:Sprite = new Sprite(); var sprite1:Sprite = new Sprite(); var sprite2:Sprite = new Sprite(); var sprite3:Sprite = new Sprite(); container.addChild(sprite1); container.addChild(sprite2); container.addChildAt(sprite3, 0); trace(container.getChildAt(0) == sprite3); // true trace(container.getChildAt(1) == sprite1); // true trace(container.getChildAt(2) == sprite2); // true
| getChildByName | () | method |
public function getChildByName(name:String):DisplayObject
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Returns the child display object that exists with the specified name. If more that one child display object has the specified name, the method returns the first object in the child list.
The getChildAt() method is faster than the
getChildByName() method. The getChildAt() method accesses
a child from a cached array, whereas the getChildByName() method
has to traverse a linked list to access a child.
Parameters
name:String — The name of the child to return.
|
DisplayObject — The child display object with the specified name.
|
SecurityError — This child display object belongs to a sandbox
to which you do not have access. You can avoid this situation by having
the child movie call the Security.allowDomain() method.
|
See also
container and then adds two child display objects to the container.
Then, the code calls the getChildByName() and getChildIndex()
methods to return the index position of the child of the container object that
has the name "sprite1".
import flash.display.Sprite;
import flash.display.DisplayObject;
var container:Sprite = new Sprite();
var sprite1:Sprite = new Sprite();
sprite1.name = "sprite1";
var sprite2:Sprite = new Sprite();
sprite2.name = "sprite2";
container.addChild(sprite1);
container.addChild(sprite2);
var target:DisplayObject = container.getChildByName("sprite1");
trace(container.getChildIndex(target)); // 0| getChildIndex | () | method |
public function getChildIndex(child:DisplayObject):int
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Returns the index position of a child DisplayObject instance.
Parameters
child:DisplayObject — The DisplayObject instance to identify.
|
int — The index position of the child display object to identify.
|
ArgumentError — Throws if the child parameter is not a child of this object.
|
container and then adds two child display objects to the container.
Then, the code calls the getChildByName() and getChildIndex()
methods to return the index position of the child of the container object that
has the name "sprite1".
import flash.display.Sprite;
import flash.display.DisplayObject;
var container:Sprite = new Sprite();
var sprite1:Sprite = new Sprite();
sprite1.name = "sprite1";
var sprite2:Sprite = new Sprite();
sprite2.name = "sprite2";
container.addChild(sprite1);
container.addChild(sprite2);
var target:DisplayObject = container.getChildByName("sprite1");
trace(container.getChildIndex(target)); // 0| getObjectsUnderPoint | () | method |
public function getObjectsUnderPoint(point:Point):Array
| Language Version : | ActionScript 3.0 |
| Player Version : | Flash Player 9 |
Returns an array of objects that lie under the specified point and are children
(or grandchildren, and so on) of this DisplayObjectContainer instance. Any child objects that
are inaccessible for security reasons are omitted from the returned array. To determine whether
this security restriction affects the returned array, call the
areInaccessibleObjectsUnderPoint() method.
The point parameter is in the coordinate space of the Stage,
which may differ from the coordinate space of the display object container (unless the
display object container is the Stage). You can use the globalToLocal() and
the localToGlobal() methods to convert points between thes