- Known Subclasses:
-
MovieClip
Stage
A Container is a nestable display lists that allows you to work with compound display elements. For
example you could group arm, leg, torso and head Bitmaps together into a Person Container, and
transform them as a group, while still being able to move the individual parts relative to each
other. Children of containers have their transform and alpha properties concatenated with their
parent Container. For example, a Shape with x=100 and alpha=0.5, placed in a Container with
x=50 and alpha=0.7 will be rendered to the canvas at x=150 and alpha=0.35. Containers have some
overhead, so you generally shouldn't create a Container to hold a single child.
Properties
children
- Array[DisplayObject]
The array of children in the display list. You should usually use the child management methods,
rather than accessing this directly, but it is included for advanced users.
Default Value: null
Properties inherited from DisplayObject:
_cacheDataURL,
_cacheDataURLID,
_cacheOffsetX,
_cacheOffsetY,
_matrix,
alpha,
cacheCanvas,
cacheID,
compositeOperation,
filters,
id,
mouseEnabled,
name,
parent,
regX,
regY,
rotation,
scaleX,
scaleY,
shadow,
skewX,
skewY,
snapToPixel,
visible,
x,
y
Methods
protected
Array[DisplayObject]
_getObjectsUnderPoint
(
x
,
y
,
arr
,
mouseEvents
)
- Parameters:
-
x
<Number>
-
y
<Number>
-
arr
<Array>
-
mouseEvents
<Number>
A bitmask indicating which mouseEvent types to look for. Bit 1 specifies onPress &
onClick & onDoubleClick, bit 2 specifies it should look for onMouseOver and onMouseOut. This implementation may change.
- Returns:
Array[DisplayObject]
DisplayObject
addChild
(
child
)
Adds a child to the top of the display list. You can also add multiple children, such as "addChild(child1, child2, ...);".
Returns the child that was added, or the last child if multiple children were added.
- Parameters:
-
child
<DisplayObject>
The display object to add.
- Returns:
DisplayObject
- The child that was added, or the last child if multiple children were added.
DisplayObject
addChildAt
(
child
,
index
)
Adds a child to the display list at the specified index, bumping children at equal or greater indexes up one, and setting
its parent to this Container. You can also add multiple children, such as "addChildAt(child1, child2, ..., index);". The
index must be between 0 and numChildren. For example, to add myShape under otherShape in the display list, you could use:
container.addChildAt(myShape, container.getChildIndex(otherShape)). This would also bump otherShape's index up by one.
Returns the last child that was added, or the last child if multiple children were added.
- Parameters:
-
child
<DisplayObject>
The display object to add.
-
index
<Number>
The index to add the child at.
- Returns:
DisplayObject
- The child that was added, or the last child if multiple children were added.
Container
clone
(
recursive
)
Returns a clone of this Container. Some properties that are specific to this instance's current context are reverted to
their defaults (for example .parent).
- Parameters:
-
recursive
<Boolean>
If true, all of the descendants of this container will be cloned recursively. If false, the
properties of the container will be cloned, but the new instance will not have any children.
- Returns:
Container
- A clone of the current Container instance.
Boolean
contains
(
child
)
Returns true if the specified display object either is this container or is a descendent.
(child, grandchild, etc) of this container.
- Parameters:
-
child
<DisplayObject>
The DisplayObject to be checked.
- Returns:
Boolean
- true if the specified display object either is this container or is a descendent.
void
draw
(
ctx
,
ignoreCache
)
Draws the display object into the specified context ignoring it's visible, alpha, shadow, and transform.
Returns true if the draw was handled (useful for overriding functionality).
NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
- Parameters:
-
ctx
<CanvasRenderingContext2D>
The canvas 2D context object to draw into.
-
ignoreCache
<Boolean>
Indicates whether the draw operation should ignore any current cache.
For example, used for drawing the cache (to prevent it from simply drawing an existing cache back
into itself).
- Returns:
void
DisplayObject
getChildAt
(
index
)
Returns the child at the specified index.
- Parameters:
-
index
<Number>
The index of the child to return.
- Returns:
DisplayObject
- The child at the specified index.
Number
getChildIndex
(
child
)
Returns the index of the specified child in the display list, or -1 if it is not in the display list.
- Parameters:
-
child
<DisplayObject>
The child to return the index of.
- Returns:
Number
- The index of the specified child. -1 if the child is not found.
Number
getNumChildren
(
)
Returns the number of children in the display list.
- Returns:
Number
- The number of children in the display list.
Array[DisplayObject]
getObjectsUnderPoint
(
x
,
y
)
Returns an array of all display objects under the specified coordinates that are in this container's display list.
This routine ignores any display objects with mouseEnabled set to false. The array will be sorted in order of visual
depth, with the top-most display object at index 0. This uses shape based hit detection, and can be an expensive operation
to run, so it is best to use it carefully. For example, if testing for objects under the mouse, test on tick (instead of on
mousemove), and only if the mouse's position has changed.
- Parameters:
-
x
<Number>
The x position in the container to test.
-
y
<Number>
The y position in the container to test.
- Returns:
Array[DisplayObject]
- An Array of DisplayObjects under the specified coordinates.
DisplayObject
getObjectUnderPoint
(
x
,
y
)
Similar to getObjectsUnderPoint(), but returns only the top-most display object. This runs significantly faster than
getObjectsUnderPoint(), but is still an expensive operation. See getObjectsUnderPoint() for more information.
- Parameters:
-
x
<Number>
The x position in the container to test.
-
y
<Number>
The y position in the container to test.
- Returns:
DisplayObject
- The top-most display object under the specified coordinates.
Boolean
hitTest
(
x
,
y
)
Tests whether the display object intersects the specified local point (ie. draws a pixel with alpha > 0 at the specified
position). This ignores the alpha, shadow and compositeOperation of the display object, and all transform properties
including regX/Y.
- Parameters:
-
x
<object>
The x position to check in the display object's local coordinates.
-
y
<object>
The y position to check in the display object's local coordinates.
- Returns:
Boolean
- A Boolean indicating whether there is a visible section of a DisplayObject that overlaps the specified
coordinates.
protected
void
initialize
(
)
Initialization method.
Boolean
isVisible
(
)
Returns true or false indicating whether the display object would be visible if drawn to a canvas.
This does not account for whether it would be visible within the boundaries of the stage.
NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
- Returns:
Boolean
- Boolean indicating whether the display object would be visible if drawn to a canvas
void
removeAllChildren
(
)
Removes all children from the display list.
Boolean
removeChild
(
child
)
Removes the specified child from the display list. Note that it is faster to use removeChildAt() if the index is already
known. You can also remove multiple children, such as "removeChild(child1, child2, ...);". Returns true if the child
(or children) was removed, or false if it was not in the display list.
- Parameters:
-
child
<DisplayObject>
The child to remove.
- Returns:
Boolean
- true if the child (or children) was removed, or false if it was not in the display list.
removeChildAt
(
index
)
Removes the child at the specified index from the display list, and sets its parent to null. You can also remove multiple
children, such as "removeChildAt(2, 7, ...);". Returns true if the child (or children) was removed, or false if any index
was out of range.
- Parameters:
-
index
<Number>
The index of the child to remove.
void
setChildIndex
(
child
,
index
)
Changes the depth of the specified child. Fails silently if the child is not a child of this container, or the index is out of range.
- Parameters:
-
child
<object>
-
index
<object>
- Returns:
void
void
sortChildren
(
sortFunction
)
Performs an array sort operation on the child list.
- Parameters:
-
sortFunction
<Function>
the function to use to sort the child list. See javascript's Array.sort documentation
for details.
- Returns:
void
void
swapChildren
(
child1
,
child2
)
Swaps the specified children's depth in the display list. Fails silently if either child is not a child of this Container.
- Parameters:
-
child1
<object>
-
child2
<object>
- Returns:
void
void
swapChildrenAt
(
index1
,
index2
)
Swaps the children at the specified indexes. Fails silently if either index is out of range.
- Parameters:
-
index1
<object>
-
index2
<object>
- Returns:
void
String
toString
(
)
Returns a string representation of this object.
- Returns:
String
- a string representation of the instance.
_applyFilters,
_testHit,
_tick,
applyShadow,
cache,
clone,
cloneProps,
draw,
getCacheDataURL.,
getConcatenatedMatrix,
getStage,
globalToLocal,
hitTest,
initialize,
isVisible,
localToGlobal,
localToLocal,
setTransform,
toString,
uncache,
updateCache