mobile-graphic-easel-src-easeljs-display-Container.js / js
A Container is a nestable display list that allows you to work with compound display elements. For example you could group arm, leg, torso and head {{#crossLink "Bitmap"}}{{/crossLink}} instances 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 <code>transform</code> and <code>alpha</code> properties concatenated with their parent Container. For example, a {{#crossLink "Shape"}}{{/crossLink}} with x=100 and alpha=0.5, placed in a Container with <code>x=50</code> and <code>alpha=0.7</code> will be rendered to the canvas at <code>x=150</code> and <code>alpha=0.35</code>. Containers have some overhead, so you generally shouldn't create a Container to hold a single child. <h4>Example</h4> var container = new createjs.Container(); container.addChild(bitmapInstance, shapeInstance); container.x = 100; @class Container @extends DisplayObject @constructor
The array of children in the display list. You should usually use the child management methods such as {{#crossLink "Container/addChild"}}{{/crossLink}}, {{#crossLink "Container/removeChild"}}{{/crossLink}}, {{#crossLink "Container/swapChildren"}}{{/crossLink}}, etc, rather than accessing this directly, but it is included for advanced users. @property children @type Array @default null
@property DisplayObject_initialize @type Function @private
Initialization method. @method initialize @protected
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. @method isVisible
returns: {Boolean} Boolean indicating whether the display object would be visible if drawn to a canvas
@property DisplayObject_draw @type Function @private
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. @method draw
parameter: {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
parameter: {Boolean} ignoreCache 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).
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. <h4>Example</h4> container.addChild(bitmapInstance, shapeInstance); @method addChild
parameter: {DisplayObject} child The display object to add.
returns: {DisplayObject} The child that was added, or the last child if multiple children were added.
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. Fails silently if the index is out of range. @method addChildAt
parameter: {DisplayObject} child The display object to add.
parameter: {Number} index The index to add the child at.
returns: {DisplayObject} The child that was added, or the last child if multiple children were added.
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. @method removeChild
parameter: {DisplayObject} child The child to remove.
returns: {Boolean} true if the child (or children) was removed, or false if it was not in the display list.
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.
parameter: {Number} index The index of the child to remove.
returns: {Boolean} true if the child (or children) was removed, or false if any index was out of range.
Removes all children from the display list. @method removeAllChildren
Returns the child at the specified index. @method getChildAt
parameter: {Number} index The index of the child to return.
returns: {DisplayObject} The child at the specified index.
Returns the child with the specified name. @method getChildByName
parameter: {String} name The name of the child to return.
returns: {DisplayObject} The child with the specified name.
Performs an array sort operation on the child list. @method sortChildren
parameter: {Function} sortFunction the function to use to sort the child list. See javascript's Array.sort documentation for details.
Returns the index of the specified child in the display list, or -1 if it is not in the display list. @method getChildIndex
parameter: {DisplayObject} child The child to return the index of.
returns: {Number} The index of the specified child. -1 if the child is not found.
Returns the number of children in the display list. @method getNumChildren
returns: {Number} The number of children in the display list.
Swaps the children at the specified indexes. Fails silently if either index is out of range.
parameter: {Number} index1
parameter: {Number} index2 @method swapChildrenAt
Swaps the specified children's depth in the display list. Fails silently if either child is not a child of this Container.
parameter: {DisplayObject} child1
parameter: {DisplayObject} child2 @method swapChildren
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.
parameter: {DisplayObject} child
parameter: {Number} index @method setChildIndex
Returns true if the specified display object either is this container or is a descendent. (child, grandchild, etc) of this container. @method contains
parameter: {DisplayObject} child The DisplayObject to be checked.
returns: {Boolean} true if the specified display object either is this container or is a descendent.
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. @method hitTest
parameter: {Number} x The x position to check in the display object's local coordinates.
parameter: {Number} y 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.
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. @method getObjectsUnderPoint
parameter: {Number} x The x position in the container to test.
parameter: {Number} y The y position in the container to test.
returns: {Array} An Array of DisplayObjects under the specified coordinates.
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. @method getObjectUnderPoint
parameter: {Number} x The x position in the container to test.
parameter: {Number} y The y position in the container to test.
returns: {DisplayObject} The top-most display object under the specified coordinates.
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).
parameter: {Boolean} recursive 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.
Returns a string representation of this object. @method toString
returns: {String} a string representation of the instance.
@property DisplayObject__tick @type Function @private
@method _tick @protected
@method _getObjectsUnderPoint
parameter: {Number} x
parameter: {Number} y
parameter: {Array} arr
parameter: {Number} mouseEvents A bitmask indicating which event types to look for. Bit 1 specifies press & click & double click, bit 2 specifies it should look for mouse over and mouse out. This implementation may change.
returns: {Array} @protected
(C) Æliens 04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.