Package | flash.display |
Class | public class DisplayObjectContainer |
Inheritance | DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object |
Subclasses | Loader, Sprite, Stage, TextLine |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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 | ||
---|---|---|---|
accessibilityImplementation : AccessibilityImplementation
The current accessibility implementation (AccessibilityImplementation)
for this InteractiveObject instance. | InteractiveObject | ||
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 | ||
blendShader : Shader [write-only]
Sets a shader that is used for blending the foreground and background. | 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 | ||
rotationX : Number
Indicates the x-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container. | DisplayObject | ||
rotationY : Number
Indicates the y-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container. | DisplayObject | ||
rotationZ : Number
Indicates the z-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container. | 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 | ||
scaleZ : Number
Indicates the depth 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 : flash.text:TextSnapshot [read-only]
Returns a TextSnapshot object for this DisplayObjectContainer instance. | DisplayObjectContainer | ||
transform : flash.geom: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 | ||
z : Number
Indicates the z coordinate position along the z-axis of the DisplayObject
instance relative to the 3D parent container. | 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 | ||
Converts a two-dimensional point from the Stage (global) coordinates to a
three-dimensional 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 bounding box of the display object to see if it overlaps or intersects with the
bounding box of 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 a three-dimensional point of the three-dimensional display
object's (local) coordinates to a two-dimensional point in the Stage (global) coordinates. | DisplayObject | ||
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 this object, formatted according to locale-specific conventions. | Object | ||
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
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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.
Implementation
public function get mouseChildren():Boolean
public function set mouseChildren(value:Boolean):void
See also
Example ( How to use this example )
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Returns the number of children of this object.
Implementation
public function get numChildren():int
Example ( How to use this example )
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
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Determines whether the children of the object are tab enabled. Enables or disables tabbing for the
children of the object. The default is true
.
Implementation
public function get tabChildren():Boolean
public function set tabChildren(value:Boolean):void
Throws
IllegalOperationError — Calling this property of the Stage object
throws an exception. The Stage object does not implement this property.
|
Example ( How to use this example )
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:flash.text:TextSnapshot
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Returns a TextSnapshot object for this DisplayObjectContainer instance.
Implementation
public function get textSnapshot():flash.text:TextSnapshot
See also
Example ( How to use this example )
trace(this.textSnapshot.getText(0, this.textSnapshot.charCount));
DisplayObjectContainer | () | Constructor |
public function DisplayObjectContainer()
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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.
|
Events
added: — Dispatched when a display object is added to the display list.
|
Throws
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
Example ( How to use this example )
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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.
|
Events
added: — Dispatched when a display object is added to the display list.
|
Throws
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
Example ( How to use this example )
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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 security chapter in the Programming ActionScript 3.0 book and the latest comments on LiveDocs
- The security chapter in the Programming ActionScript 3.0 book and the latest comments on LiveDocs
- The Flash Player Developer Center Topic: Security
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
getObjectsUnderPoint()
DisplayObject.globalToLocal()
DisplayObject.localToGlobal()
Example ( How to use this example )
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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 .
|
Example ( How to use this example )
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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.
|
Throws
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
Example ( How to use this example )
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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.
|
Throws
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
Example ( How to use this example )
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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.
|
Throws
ArgumentError — Throws if the child parameter is not a child of this object.
|
Example ( How to use this example )
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 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
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 these coordinate
spaces.
Parameters
point:Point — The point under which to look.
|
Array — An array of objects that lie under the specified point and are children
(or grandchildren, and so on) of this DisplayObjectContainer instance.
|
See also
Example ( How to use this example )
container
and then adds two overlapping child display objects to the container. Then the code calls the
getObjectsUnderPoint()
twice — first using a point that touches only one object,
then using a point where the objects overlap — and the length
of the return
Array shows the number of objects at each point in the container:
import flash.display.Sprite; import flash.geom.Point; var container:Sprite = new Sprite(); var square1:Sprite = new Sprite(); square1.graphics.beginFill(0xFFCC00); square1.graphics.drawRect(0, 0, 40, 40); var square2:Sprite = new Sprite(); square2.graphics.beginFill(0x00CCFF); square2.graphics.drawRect(20, 0, 30, 40); container.addChild(square1); container.addChild(square2); var pt:Point = new Point(10, 20); var objects:Array = container.getObjectsUnderPoint(pt); trace(objects.length); // 1 pt = new Point(35, 20); objects = container.getObjectsUnderPoint(pt); trace(objects.length); // 2
removeChild | () | method |
public function removeChild(child:DisplayObject):DisplayObject
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Removes the specified child
DisplayObject instance from the child list of the DisplayObjectContainer instance.
The parent
property of the removed child is set to null
, and the object is garbage collected if no other
references to the child exist. The index positions of any display objects above the child in the
DisplayObjectContainer are decreased by 1.
The garbage collector reallocates unused memory space. When a variable or object is no longer actively referenced or stored somewhere, the garbage collector sweeps through and wipes out the memory space it used to occupy if no other references to it exist.
Parameters
child:DisplayObject — The DisplayObject instance to remove.
|
DisplayObject — The DisplayObject instance that you pass in the
child parameter.
|
Throws
ArgumentError — Throws if the child parameter is not a child of this object.
|
Example ( How to use this example )
container
and then adds two child display objects to the container.
An event listener is added to the container
object, so that when the
user clicks a child object of the container, the removeChild()
method
removes the child clicked from the child list of the container:
import flash.display.DisplayObject; import flash.display.Sprite; import flash.events.MouseEvent; var container:Sprite = new Sprite(); addChild(container); 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(120, 40, 40); container.addChild(circle1); container.addChild(circle2); container.addEventListener(MouseEvent.CLICK, clicked); function clicked(event:MouseEvent):void { container.removeChild(DisplayObject(event.target)); }
removeChildAt | () | method |
public function removeChildAt(index:int):DisplayObject
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Removes a child DisplayObject from the specified index
position in the child list of
the DisplayObjectContainer. The parent
property of the removed child is set to
null
, and the object is garbage collected if no other references to the child exist. The index
positions of any display objects above the child in the DisplayObjectContainer are decreased by 1.
The garbage collector reallocates unused memory space. When a variable or object is no longer actively referenced or stored somewhere, the garbage collector sweeps through and wipes out the memory space it used to occupy if no other references to it exist.
Parameters
index:int — The child index of the DisplayObject to remove.
|
DisplayObject — The DisplayObject instance that was removed.
|
Throws
SecurityError — This child display object belongs to a sandbox
to which the calling object does not have access. You can avoid this situation by having
the child movie call the Security.allowDomain() method.
| |
RangeError — Throws if the index does not exist in the child list.
|
Example ( How to use this example )
container
and then adds two child display objects to the container.
The code then shows that when you call the removeChildAt()
method
to remove the child at the lowest index position (0), any other child object in the list
moves down one position:
import flash.display.Sprite; 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); trace(container.numChildren) // 2 container.removeChildAt(0); trace(container.numChildren) // 1 trace(container.getChildAt(0).name); // sprite2
setChildIndex | () | method |
public function setChildIndex(child:DisplayObject, index:int):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Changes the position of an existing child in the display object container. This affects the layering of child objects. For example, the following example shows three display objects, labeled a, b, and c, at index positions 0, 1, and 2, respectively:
When you use the setChildIndex()
method and specify an index position
that is already occupied, the only positions that change are those in between the display object's former and new position.
All others will stay the same.
If a child is moved to an index LOWER than its current index, all children in between will INCREASE by 1 for their index reference.
If a child is moved to an index HIGHER than its current index, all children in between will DECREASE by 1 for their index reference.
For example, if the display object container
in the previous example is named container
, you can swap the position
of the display objects labeled a and b by calling the following code:
container.setChildIndex(container.getChildAt(1), 0);
This code results in the following arrangement of objects:
Parameters
child:DisplayObject — The child DisplayObject instance for which you want to change
the index number.
| |
index:int — The resulting index number for the child display object.
|
Throws
RangeError — Throws if the index does not exist in the child list.
| |
ArgumentError — Throws if the child parameter is not a child of this object.
|
See also
Example ( How to use this example )
container
and then adds three slightly overlapping child display
objects to the container. When the user clicks any of these objects, the
clicked()
method calls the setChildIndex()
method to move the clicked object to the top-most position in the child list of
the container
object:
import flash.display.Sprite; import flash.events.MouseEvent; var container:Sprite = new Sprite(); addChild(container); var circle1:Sprite = new Sprite(); circle1.graphics.beginFill(0xFF0000); circle1.graphics.drawCircle(40, 40, 40); circle1.addEventListener(MouseEvent.CLICK, clicked); var circle2:Sprite = new Sprite(); circle2.graphics.beginFill(0x00FF00); circle2.graphics.drawCircle(100, 40, 40); circle2.addEventListener(MouseEvent.CLICK, clicked); var circle3:Sprite = new Sprite(); circle3.graphics.beginFill(0x0000FF); circle3.graphics.drawCircle(70, 80, 40); circle3.addEventListener(MouseEvent.CLICK, clicked); container.addChild(circle1); container.addChild(circle2); container.addChild(circle3); addChild(container); function clicked(event:MouseEvent):void { var circle:Sprite = Sprite(event.target); var topPosition:uint = container.numChildren - 1; container.setChildIndex(circle, topPosition); }
swapChildren | () | method |
public function swapChildren(child1:DisplayObject, child2:DisplayObject):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Swaps the z-order (front-to-back order) of the two specified child objects. All other child objects in the display object container remain in the same index positions.
Parameters
child1:DisplayObject — The first child object.
| |
child2:DisplayObject — The second child object.
|
Throws
ArgumentError — Throws if either child parameter is not a child of this object.
|
Example ( How to use this example )
container
, then adds two child display objects to the container,
and then shows the effect of a call to the swapChildren()
method:
import flash.display.Sprite; 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); trace(container.getChildAt(0).name); // sprite1 trace(container.getChildAt(1).name); // sprite2 container.swapChildren(sprite1, sprite2); trace(container.getChildAt(0).name); // sprite2 trace(container.getChildAt(1).name); // sprite1
swapChildrenAt | () | method |
public function swapChildrenAt(index1:int, index2:int):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
Swaps the z-order (front-to-back order) of the child objects at the two specified index positions in the child list. All other child objects in the display object container remain in the same index positions.
Parameters
index1:int — The index position of the first child object.
| |
index2:int — The index position of the second child object.
|
Throws
RangeError — If either index does not exist in the child list.
|
Example ( How to use this example )
container
, then adds three child display objects to the container,
and then shows how a call to the swapChildrenAt()
method rearranges
the child list of the display object container:
import flash.display.Sprite; var container:Sprite = new Sprite(); var sprite1:Sprite = new Sprite(); sprite1.name = "sprite1"; var sprite2:Sprite = new Sprite(); sprite2.name = "sprite2"; var sprite3:Sprite = new Sprite(); sprite3.name = "sprite3"; container.addChild(sprite1); container.addChild(sprite2); container.addChild(sprite3); trace(container.getChildAt(0).name); // sprite1 trace(container.getChildAt(1).name); // sprite2 trace(container.getChildAt(2).name); // sprite3 container.swapChildrenAt(0, 2); trace(container.getChildAt(0).name); // sprite3 trace(container.getChildAt(1).name); // sprite2 trace(container.getChildAt(2).name); // sprite1
DisplayObjectContainerExample
to
create five orange squares in succession. This task is accomplished by performing the following steps:
- The constructor calls the
configureAssets()
method. - The
configureAssets()
method createschild
andlastChild
Sprite objects. - A
for
loop creates the five orange squares and positions them one after another. - Each time a CustomSprite object is created, its constructor calls the
draw()
method of theCustomSprite
object, which creates a 50-by-50-pixel square by calling thebeginFill()
,drawRect()
, andendFill()
methods of the Graphics class. TheaddChild()
method adds each square to the display list.
package { import flash.display.DisplayObject; import flash.display.Sprite; public class DisplayObjectContainerExample extends Sprite { private var gutter:uint = 5; private var childCount:uint = 5; public function DisplayObjectContainerExample() { configureAssets(); } private function configureAssets():void { var child:Sprite = new CustomSprite(); var lastChild:Sprite = child; for (var i:uint = 1; i <= childCount; i++) { child = new CustomSprite(); child.x = lastChild.x + lastChild.width + gutter; addChild(child); lastChild = child; } } } } import flash.display.Sprite; class CustomSprite extends Sprite { private var size:uint = 50; private var bgColor:uint = 0xFFCC00; public function CustomSprite() { draw(size, size); } private function draw(w:uint, h:uint):void { graphics.beginFill(bgColor); graphics.drawRect(0, 0, w, h); graphics.endFill(); } }
Fri Mar 19 2010, 02:45 AM -07:00