Dart DocumentationstagexlDisplayObjectContainer

DisplayObjectContainer abstract class

abstract class DisplayObjectContainer extends InteractiveObject {

 final List<DisplayObject> _children = new List<DisplayObject>();
 bool _mouseChildren = true;
 bool _tabChildren = true;

 //-------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------

 int get numChildren => _children.length;

 bool get mouseChildren => _mouseChildren;
 bool get tabChildren => _tabChildren;

 void set mouseChildren(bool value) { _mouseChildren = value; }
 void set tabChildren(bool value) { _tabChildren = value; }

 //-------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------

 void addChild(DisplayObject child) {
   addChildAt(child, _children.length);
 }

 //-------------------------------------------------------------------------------------------------

 void addChildAt(DisplayObject child, int index) {

   if (index < 0 || index > _children.length) {
     throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
   }

   if (child == this) {
     throw new ArgumentError("Error #2024: An object cannot be added as a child of itself.");
   }

   if (child.parent == this) {

     _children.remove(child);
     if (index > _children.length) index -= 1;
     _children.insert(index, child);

   } else {

     child.removeFromParent();

     for(var ancestor = this; ancestor != null; ancestor = ancestor.parent) {
       if (ancestor == child) {
         throw new ArgumentError("Error #2150: An object cannot be added as "
             "a child to one of it's children (or children's children, etc.).");
       }
     }

     _children.insert(index, child);

     child._parent = this;
     child.dispatchEvent(new Event(Event.ADDED, true));

     if (this.stage != null) {
       _dispatchEventDescendants(child, new Event(Event.ADDED_TO_STAGE));
     }
   }
 }

 //-------------------------------------------------------------------------------------------------

 void removeChild(DisplayObject child) {

   int childIndex = _children.indexOf(child);
   if (childIndex == -1) {
     throw new ArgumentError(
         "Error #2025: The supplied DisplayObject must be a child of the caller.");
   }

   removeChildAt(childIndex);
 }

 //-------------------------------------------------------------------------------------------------

 void removeChildAt(int index) {

   if (index < 0 || index >= _children.length) {
     throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
   }

   DisplayObject child = _children[index];

   child.dispatchEvent(new Event(Event.REMOVED, true));

   if (this.stage != null) {
     _dispatchEventDescendants(child, new Event(Event.REMOVED_FROM_STAGE));
   }

   child._parent = null;
   _children.removeAt(index);
 }

 //-------------------------------------------------------------------------------------------------

 void removeChildren([int beginIndex = 0, int endIndex = 0x7fffffff]) {

   var length = _children.length;
   if (length == 0) return;

   if (endIndex == 0x7fffffff) {
     endIndex = length - 1;
   }

   if (beginIndex < 0 || endIndex < 0 || beginIndex >= length || endIndex >= length) {
     throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
   }

   for(int i = beginIndex; i <= endIndex; i++) {
     if (beginIndex >= _children.length) break;
     removeChildAt(beginIndex);
   }
 }

 //-------------------------------------------------------------------------------------------------

 dynamic getChildAt(int index) {

   if (index < 0 || index >= _children.length) {
     throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
   }
   return _children[index];
 }

 //-------------------------------------------------------------------------------------------------

 dynamic getChildByName(String name) {

   for(int i = 0; i < _children.length; i++) {
     DisplayObject child = _children[i];
     if (child.name == name) return child;
   }
   return null;
 }

 //-------------------------------------------------------------------------------------------------

 int getChildIndex(DisplayObject child) {

   return _children.indexOf(child);
 }

 //-------------------------------------------------------------------------------------------------

 void setChildIndex(DisplayObject child, int index) {

   if (index < 0 || index >= _children.length) {
     throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
   }

   int oldIndex = getChildIndex(child);
   if (oldIndex == -1) {
     throw new ArgumentError("Error #2025: The supplied DisplayObject must be a child of the caller.");
   }

   _children.removeAt(oldIndex);
   _children.insert(index, child);
 }

 //-------------------------------------------------------------------------------------------------

 void swapChildren(DisplayObject child1, DisplayObject child2) {

   int index1 = getChildIndex(child1);
   int index2 = getChildIndex(child2);

   if (index1 == -1 || index2 == -1) {
     throw new ArgumentError("Error #2025: The supplied DisplayObject must be a child of the caller.");
   }

   swapChildrenAt(index1, index2);
 }

 //-------------------------------------------------------------------------------------------------

 void swapChildrenAt(int index1, int index2) {

   DisplayObject child1 = getChildAt(index1);
   DisplayObject child2 = getChildAt(index2);
   _children[index1] = child2;
   _children[index2] = child1;
 }

 //-------------------------------------------------------------------------------------------------

 void sortChildren(Function compareFunction) {
   _children.sort(compareFunction);
 }

 //-------------------------------------------------------------------------------------------------

 bool contains(DisplayObject child) {

   while(child != null) {
     if (child == this) return true;
     child = child.parent;
   }
   return false;
 }

 //-------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------

 Rectangle getBoundsTransformed(Matrix matrix, [Rectangle returnRectangle]) {

   if (returnRectangle == null) {
     returnRectangle = new Rectangle.zero();
   }

   if (_children.length == 0) {
     return super.getBoundsTransformed(matrix, returnRectangle);
   }

   num left = double.INFINITY;
   num top = double.INFINITY;
   num right = double.NEGATIVE_INFINITY;
   num bottom = double.NEGATIVE_INFINITY;

   int childrenLength = _children.length;

   for (int i = 0; i < _children.length; i++) {

     DisplayObject child = _children[i];

     _tmpMatrix.copyFromAndConcat(child.transformationMatrix, matrix);
     Rectangle rectangle = child.getBoundsTransformed(_tmpMatrix, returnRectangle);

     if (rectangle.left < left) left = rectangle.left;
     if (rectangle.top < top ) top = rectangle.top;
     if (rectangle.right > right) right = rectangle.right;
     if (rectangle.bottom > bottom) bottom = rectangle.bottom;
   }

   returnRectangle.x = left;
   returnRectangle.y = top;
   returnRectangle.width = right - left;
   returnRectangle.height = bottom - top;

   return returnRectangle;
 }

 //-------------------------------------------------------------------------------------------------

 DisplayObject hitTestInput(num localX, num localY) {

   localX = localX.toDouble();
   localY = localY.toDouble();

   DisplayObject hit = null;

   for (int i = _children.length - 1; i >= 0; i--) {

     var child = _children[i];
     var mask = child.mask;
     var matrix = child.transformationMatrix;

     if (child.visible && child.off == false) {

       num deltaX = localX - matrix.tx;
       num deltaY = localY - matrix.ty;
       num childX = (matrix.d * deltaX - matrix.c * deltaY) / matrix.det;
       num childY = (matrix.a * deltaY - matrix.b * deltaX) / matrix.det;
       num maskX = 0.0;
       num maskY = 0.0;

       if (mask != null) {
         if (mask.targetSpace == null) {
           maskX = childX;
           maskY = childY;
         } else if (identical(mask.targetSpace, child)) {
           maskX = childX;
           maskY = childY;
         } else if (identical(mask.targetSpace, this)) {
           maskX = localX;
           maskY = localY;
         } else {
           matrix = this.transformationMatrixTo(mask.targetSpace);
           matrix = (matrix != null) ? matrix : _identityMatrix;
           maskX = localX * matrix.a + localY * matrix.c + matrix.tx;
           maskY = localX * matrix.b + localY * matrix.d + matrix.ty;
         }
         if (mask.hitTest(maskX, maskY) == false) continue;
       }

       var displayObject = child.hitTestInput(childX, childY);
       if (displayObject == null) continue;

       if (displayObject is InteractiveObject && displayObject.mouseEnabled) {
         return _mouseChildren ? displayObject : this;
       }

       hit = this;
     }
   }

   return hit;
 }

 //-------------------------------------------------------------------------------------------------

 void render(RenderState renderState) {

   for(int i = 0; i < _children.length; i++) {
     DisplayObject child = _children[i];
     if (child.visible && child.off == false) {
       renderState.renderDisplayObject(child);
     }
   }
 }

 //-------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------

 _collectDescendants(DisplayObject displayObject, List descendants) {

   descendants.add(displayObject);

   if (displayObject is DisplayObjectContainer) {
     var children = displayObject._children;
     for(int i = 0; i < children.length; i++) {
       _collectDescendants(children[i], descendants);
     }
   }
 }

 _dispatchEventDescendants(DisplayObject displayObject, Event event) {

   List descendants = [];
   _collectDescendants(displayObject, descendants);

   for(int i = 0; i < descendants.length; i++) {
     descendants[i].dispatchEvent(event);
   }
 }


}

Extends

EventDispatcher > DisplayObject > InteractiveObject > DisplayObjectContainer

Subclasses

Sprite, Stage, Warp

Properties

num alpha #

inherited from DisplayObject
num get alpha => _alpha;
set alpha(num value) {
 if (value is num) {
   if (value < 0.0) value = 0.0;
   if (value > 1.0) value = 1.0;
   _alpha = value;
 }
}

final bool cached #

inherited from DisplayObject
bool get cached => _cacheTexture != null;

String compositeOperation #

inherited from DisplayObject
String get compositeOperation => _compositeOperation;
set compositeOperation(String value) {
 _compositeOperation = value;
}

bool doubleClickEnabled #

inherited from InteractiveObject
bool doubleClickEnabled = false

List<BitmapFilter> filters #

inherited from DisplayObject
List<BitmapFilter> get filters {
 if (_filters == null) _filters = new List<BitmapFilter>();
 return _filters;
}
set filters(List<BitmapFilter> value) {
 _filters = value;
}

num height #

inherited from DisplayObject
num get height => getBoundsTransformed(this.transformationMatrix).height;
void set height(num value) {
 this.scaleY = 1;
 num normalHeight = this.height;
 this.scaleY = (normalHeight != 0.0) ? value / normalHeight : 1.0;
}

Mask mask #

inherited from DisplayObject
Mask get mask => _mask;
set mask(Mask value) {
 _mask = value;
}

bool mouseChildren #

bool get mouseChildren => _mouseChildren;
void set mouseChildren(bool value) { _mouseChildren = value; }

bool mouseEnabled #

inherited from InteractiveObject
bool mouseEnabled = true

final Point mousePosition #

inherited from DisplayObject
Point get mousePosition {
 var stage = this.stage;
 return (stage != null) ? this.globalToLocal(stage._mousePosition) : null;
}

final num mouseX #

inherited from DisplayObject
num get mouseX {
 var mp = this.mousePosition;
 return (mp != null) ? mp.x : 0.0;
}

final num mouseY #

inherited from DisplayObject
num get mouseY {
 var mp = this.mousePosition;
 return (mp != null) ? mp.y : 0.0;
}

String name #

inherited from DisplayObject
String get name => _name;
set name(String value) {
 _name = value;
}

final int numChildren #

int get numChildren => _children.length;

bool off #

inherited from DisplayObject
bool get off => _off;
set off(bool value) {
 if (value is bool) _off = value;
}

final EventStream<Event> onAdded #

inherited from DisplayObject
EventStream<Event> get onAdded => DisplayObject.addedEvent.forTarget(this);

final EventStream<Event> onAddedToStage #

inherited from DisplayObject
EventStream<Event> get onAddedToStage => DisplayObject.addedToStageEvent.forTarget(this);

final EventStream<EnterFrameEvent> onEnterFrame #

inherited from DisplayObject
EventStream<EnterFrameEvent> get onEnterFrame => DisplayObject.enterFrameEvent.forTarget(this);

final EventStream<ExitFrameEvent> onExitFrame #

inherited from DisplayObject
EventStream<ExitFrameEvent> get onExitFrame => DisplayObject.exitFrameEvent.forTarget(this);

final EventStream<KeyboardEvent> onKeyDown #

inherited from InteractiveObject
EventStream<KeyboardEvent> get onKeyDown => InteractiveObject.keyDownEvent.forTarget(this);

final EventStream<KeyboardEvent> onKeyUp #

inherited from InteractiveObject
EventStream<KeyboardEvent> get onKeyUp => InteractiveObject.keyUpEvent.forTarget(this);

final EventStream<MouseEvent> onMouseClick #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseClick => InteractiveObject.mouseClickEvent.forTarget(this);

final EventStream<MouseEvent> onMouseContextMenu #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseContextMenu => InteractiveObject.mouseContextMenu.forTarget(this);

final EventStream<MouseEvent> onMouseDoubleClick #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseDoubleClick => InteractiveObject.mouseDoubleClickEvent.forTarget(this);

final EventStream<MouseEvent> onMouseDown #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseDown => InteractiveObject.mouseDownEvent.forTarget(this);

final EventStream<MouseEvent> onMouseMiddleClick #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseMiddleClick => InteractiveObject.mouseMiddleClickEvent.forTarget(this);

final EventStream<MouseEvent> onMouseMiddleDown #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseMiddleDown => InteractiveObject.mouseMiddleDownEvent.forTarget(this);

final EventStream<MouseEvent> onMouseMiddleUp #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseMiddleUp => InteractiveObject.mouseMiddleUpEvent.forTarget(this);

final EventStream<MouseEvent> onMouseMove #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseMove => InteractiveObject.mouseMoveEvent.forTarget(this);

final EventStream<MouseEvent> onMouseOut #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseOut => InteractiveObject.mouseOutEvent.forTarget(this);

final EventStream<MouseEvent> onMouseOver #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseOver => InteractiveObject.mouseOverEvent.forTarget(this);

final EventStream<MouseEvent> onMouseRightClick #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseRightClick => InteractiveObject.mouseRightClickEvent.forTarget(this);

final EventStream<MouseEvent> onMouseRightDown #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseRightDown => InteractiveObject.mouseRightDownEvent.forTarget(this);

final EventStream<MouseEvent> onMouseRightUp #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseRightUp => InteractiveObject.mouseRightUpEvent.forTarget(this);

final EventStream<MouseEvent> onMouseRollOut #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseRollOut => InteractiveObject.mouseRollOutEvent.forTarget(this);

final EventStream<MouseEvent> onMouseRollOver #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseRollOver => InteractiveObject.mouseRollOverEvent.forTarget(this);

final EventStream<MouseEvent> onMouseUp #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseUp => InteractiveObject.mouseUpEvent.forTarget(this);

final EventStream<MouseEvent> onMouseWheel #

inherited from InteractiveObject
EventStream<MouseEvent> get onMouseWheel => InteractiveObject.mouseWheelEvent.forTarget(this);

final EventStream<Event> onRemoved #

inherited from DisplayObject
EventStream<Event> get onRemoved => DisplayObject.removedEvent.forTarget(this);

final EventStream<Event> onRemovedFromStage #

inherited from DisplayObject
EventStream<Event> get onRemovedFromStage => DisplayObject.removedFromStageEvent.forTarget(this);

final EventStream<RenderEvent> onRender #

inherited from DisplayObject
EventStream<RenderEvent> get onRender => DisplayObject.renderEvent.forTarget(this);

final EventStream<TextEvent> onTextInput #

inherited from InteractiveObject
EventStream<TextEvent> get onTextInput => InteractiveObject.textInputEvent.forTarget(this);

final EventStream<TouchEvent> onTouchBegin #

inherited from InteractiveObject
EventStream<TouchEvent> get onTouchBegin => InteractiveObject.touchBeginEvent.forTarget(this);

final EventStream<TouchEvent> onTouchCancel #

inherited from InteractiveObject
EventStream<TouchEvent> get onTouchCancel => InteractiveObject.touchCancelEvent.forTarget(this);

final EventStream<TouchEvent> onTouchEnd #

inherited from InteractiveObject
EventStream<TouchEvent> get onTouchEnd => InteractiveObject.touchEndEvent.forTarget(this);

final EventStream<TouchEvent> onTouchMove #

inherited from InteractiveObject
EventStream<TouchEvent> get onTouchMove => InteractiveObject.touchMoveEvent.forTarget(this);

final EventStream<TouchEvent> onTouchOut #

inherited from InteractiveObject
EventStream<TouchEvent> get onTouchOut => InteractiveObject.touchOutEvent.forTarget(this);

final EventStream<TouchEvent> onTouchOver #

inherited from InteractiveObject
EventStream<TouchEvent> get onTouchOver => InteractiveObject.touchOverEvent.forTarget(this);

final DisplayObjectContainer parent #

inherited from DisplayObject
DisplayObjectContainer get parent => _parent;

num pivotX #

inherited from DisplayObject
num get pivotX => _pivotX;
set pivotX(num value) {
 if (value is num) _pivotX = value;
 _transformationMatrixRefresh = true;
}

num pivotY #

inherited from DisplayObject
num get pivotY => _pivotY;
set pivotY(num value) {
 if (value is num) _pivotY = value;
 _transformationMatrixRefresh = true;
}

final DisplayObject root #

inherited from DisplayObject
DisplayObject get root {

 DisplayObject currentObject = this;

 while (currentObject._parent != null)
   currentObject = currentObject._parent;

 return currentObject;
}

num rotation #

inherited from DisplayObject
num get rotation => _rotation;
set rotation(num value) {
 if (value is num) _rotation = value;
 _transformationMatrixRefresh = true;
}

num scaleX #

inherited from DisplayObject
num get scaleX => _scaleX;
set scaleX(num value) {
 if (value is num) _scaleX = value;
 _transformationMatrixRefresh = true;
}

num scaleY #

inherited from DisplayObject
num get scaleY => _scaleY;
set scaleY(num value) {
 if (value is num) _scaleY = value;
 _transformationMatrixRefresh = true;
}

Shadow shadow #

inherited from DisplayObject
Shadow get shadow => _shadow;
set shadow(Shadow value) {
 _shadow = value;
}

num skewX #

inherited from DisplayObject
num get skewX => _skewX;
set skewX(num value) {
 if (value is num) _skewX = value;
 _transformationMatrixRefresh = true;
}

num skewY #

inherited from DisplayObject
num get skewY => _skewY;
set skewY(num value) {
 if (value is num) _skewY = value;
 _transformationMatrixRefresh = true;
}

final Stage stage #

inherited from DisplayObject
Stage get stage {

 DisplayObject root = this.root;
 return (root is Stage) ? root : null;
}

bool tabChildren #

bool get tabChildren => _tabChildren;
void set tabChildren(bool value) { _tabChildren = value; }

bool tabEnabled #

inherited from InteractiveObject
bool tabEnabled = true

int tabIndex #

inherited from InteractiveObject
int tabIndex = 0

final Matrix transformationMatrix #

inherited from DisplayObject
Matrix get transformationMatrix {
 /*
 _transformationMatrix.identity();
 _transformationMatrix.translate(-_pivotX, -_pivotY);
 _transformationMatrix.scale(_scaleX, _scaleY);
 _transformationMatrix.rotate(_rotation);
 _transformationMatrix.translate(_x, _y);
 */

 if (_transformationMatrixRefresh) {

   _transformationMatrixRefresh = false;

   num skewXrotation =  _skewX + _rotation;
   num skewYrotation =  _skewY + _rotation;
   num scaleX = _scaleX;
   num scaleY = _scaleY;
   num pivotX = _pivotX;
   num pivotY = _pivotY;

   // ToDo: https://bugzilla.mozilla.org/show_bug.cgi?id=661452
   if (scaleX > -0.0001 && scaleX < 0.0001) scaleX = (scaleX >= 0) ? 0.0001 : -0.0001;
   if (scaleY > -0.0001 && scaleY < 0.0001) scaleY = (scaleY >= 0) ? 0.0001 : -0.0001;

   if (skewXrotation == 0.0 && skewYrotation == 0.0) {

     _transformationMatrix.setTo(scaleX, 0.0, 0.0, scaleY, _x - pivotX * scaleX, _y - pivotY * scaleY);

   } else {

     num a, b, c, d;
     num cosX = cos(skewXrotation);
     num sinX = sin(skewXrotation);

     if (skewXrotation == skewYrotation) {
       a =   scaleX * cosX;
       b =   scaleX * sinX;
       c = - scaleY * sinX;
       d =   scaleY * cosX;
     } else {
       a =   scaleX * cos(skewYrotation);
       b =   scaleX * sin(skewYrotation);
       c = - scaleY * sinX;
       d =   scaleY * cosX;
     }

     num tx =  _x - (pivotX * a + pivotY * c);
     num ty =  _y - (pivotX * b + pivotY * d);

     _transformationMatrix.setTo(a, b, c, d, tx, ty);
   }
 }

 return _transformationMatrix;
}

var userData #

inherited from DisplayObject

Gets or sets user-defined data associated with the display object.

dynamic userData = null

bool visible #

inherited from DisplayObject
bool get visible => _visible;
set visible(bool value) {
 if (value is bool) _visible = value;
}

num width #

inherited from DisplayObject
num get width => getBoundsTransformed(this.transformationMatrix).width;
void set width(num value) {
 this.scaleX = 1;
 num normalWidth = this.width;
 this.scaleX = (normalWidth != 0.0) ? value / normalWidth : 1.0;
}

num x #

inherited from DisplayObject
num get x => _x;
set x(num value) {
 if (value is num) _x = value;
 _transformationMatrixRefresh = true;
}

num y #

inherited from DisplayObject
num get y => _y;
set y(num value) {
 if (value is num) _y = value;
 _transformationMatrixRefresh = true;
}

Methods

void addChild(DisplayObject child) #

void addChild(DisplayObject child) {
 addChildAt(child, _children.length);
}

void addChildAt(DisplayObject child, int index) #

void addChildAt(DisplayObject child, int index) {

 if (index < 0 || index > _children.length) {
   throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
 }

 if (child == this) {
   throw new ArgumentError("Error #2024: An object cannot be added as a child of itself.");
 }

 if (child.parent == this) {

   _children.remove(child);
   if (index > _children.length) index -= 1;
   _children.insert(index, child);

 } else {

   child.removeFromParent();

   for(var ancestor = this; ancestor != null; ancestor = ancestor.parent) {
     if (ancestor == child) {
       throw new ArgumentError("Error #2150: An object cannot be added as "
           "a child to one of it's children (or children's children, etc.).");
     }
   }

   _children.insert(index, child);

   child._parent = this;
   child.dispatchEvent(new Event(Event.ADDED, true));

   if (this.stage != null) {
     _dispatchEventDescendants(child, new Event(Event.ADDED_TO_STAGE));
   }
 }
}

StreamSubscription<Event> addEventListener(String eventType, EventListener eventListener, {bool useCapture: false, int priority: 0}) #

inherited from EventDispatcher
StreamSubscription<Event> addEventListener(String eventType, EventListener eventListener, {
 bool useCapture: false, int priority: 0 }) {

 return this.on(eventType)._subscribe(eventListener, useCapture, priority);
}

void addTo(DisplayObjectContainer parent) #

inherited from DisplayObject
void addTo(DisplayObjectContainer parent) {
 parent.addChild(this);
}

void applyCache(int x, int y, int width, int height, {bool debugBorder: false}) #

inherited from DisplayObject
void applyCache(int x, int y, int width, int height, {bool debugBorder: false}) {

 var pixelRatio = Stage.autoHiDpi ? _devicePixelRatio : 1.0;

 if (_cacheTexture == null) {
   _cacheTexture = new RenderTexture(width, height, true, Color.Transparent, pixelRatio);
 } else {
   _cacheTexture.resize(width, height);
 }

 _cacheRectangle = new Rectangle(x, y, width, height);
 _cacheDebugBorder = debugBorder;

 refreshCache();
}

bool contains(DisplayObject child) #

bool contains(DisplayObject child) {

 while(child != null) {
   if (child == this) return true;
   child = child.parent;
 }
 return false;
}

void dispatchEvent(Event event) #

inherited from DisplayObject
void dispatchEvent(Event event) {

 List<DisplayObject> ancestors = null;

 if (event.captures || event.bubbles) {
   for(DisplayObject ancestor = parent; ancestor != null; ancestor = ancestor.parent) {
     if(ancestor._hasPropagationEventListeners(event)) {
       if (ancestors == null) ancestors = [];
       ancestors.add(ancestor);
     }
   }
 }

 if (ancestors != null && event.captures) {
   for(int i = ancestors.length - 1 ; i >= 0; i--) {
     ancestors[i]._dispatchEventInternal(event, this, EventPhase.CAPTURING_PHASE);
     if (event.stopsPropagation) return;
   }
 }

 _dispatchEventInternal(event, this, EventPhase.AT_TARGET);
 if (event.stopsPropagation) return;

 if (ancestors != null && event.bubbles) {
   for(int i = 0; i < ancestors.length; i++) {
     ancestors[i]._dispatchEventInternal(event, this, EventPhase.BUBBLING_PHASE);
     if (event.stopsPropagation) return;
   }
 }
}

Rectangle getBounds(DisplayObject targetSpace) #

inherited from DisplayObject
Rectangle getBounds(DisplayObject targetSpace) {

 Rectangle returnRectangle = new Rectangle.zero();
 Matrix matrix = (targetSpace == null) ? transformationMatrix : transformationMatrixTo(targetSpace);

 return (matrix != null) ? getBoundsTransformed(matrix, returnRectangle) : returnRectangle;
}

Rectangle getBoundsTransformed(Matrix matrix, [Rectangle returnRectangle]) #

Rectangle getBoundsTransformed(Matrix matrix, [Rectangle returnRectangle]) {

 if (returnRectangle == null) {
   returnRectangle = new Rectangle.zero();
 }

 if (_children.length == 0) {
   return super.getBoundsTransformed(matrix, returnRectangle);
 }

 num left = double.INFINITY;
 num top = double.INFINITY;
 num right = double.NEGATIVE_INFINITY;
 num bottom = double.NEGATIVE_INFINITY;

 int childrenLength = _children.length;

 for (int i = 0; i < _children.length; i++) {

   DisplayObject child = _children[i];

   _tmpMatrix.copyFromAndConcat(child.transformationMatrix, matrix);
   Rectangle rectangle = child.getBoundsTransformed(_tmpMatrix, returnRectangle);

   if (rectangle.left < left) left = rectangle.left;
   if (rectangle.top < top ) top = rectangle.top;
   if (rectangle.right > right) right = rectangle.right;
   if (rectangle.bottom > bottom) bottom = rectangle.bottom;
 }

 returnRectangle.x = left;
 returnRectangle.y = top;
 returnRectangle.width = right - left;
 returnRectangle.height = bottom - top;

 return returnRectangle;
}

dynamic getChildAt(int index) #

dynamic getChildAt(int index) {

 if (index < 0 || index >= _children.length) {
   throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
 }
 return _children[index];
}

dynamic getChildByName(String name) #

dynamic getChildByName(String name) {

 for(int i = 0; i < _children.length; i++) {
   DisplayObject child = _children[i];
   if (child.name == name) return child;
 }
 return null;
}

int getChildIndex(DisplayObject child) #

int getChildIndex(DisplayObject child) {

 return _children.indexOf(child);
}

Point globalToLocal(Point globalPoint) #

inherited from DisplayObject
Point globalToLocal(Point globalPoint) {

 _tmpMatrix.identity();

 for(var current = this; current != null; current = current._parent) {
   _tmpMatrix.concat(current.transformationMatrix);
 }

 _tmpMatrix.invert();

 return _tmpMatrix.transformPoint(globalPoint);
}

bool hasEventListener(String eventType) #

inherited from EventDispatcher
bool hasEventListener(String eventType) {

 var eventStreams = _eventStreams;
 if (eventStreams == null) return false;
 var eventStream = eventStreams[eventType];
 if (eventStream == null) return false;

 return eventStream.hasSubscriptions;
}

DisplayObject hitTestInput(num localX, num localY) #

DisplayObject hitTestInput(num localX, num localY) {

 localX = localX.toDouble();
 localY = localY.toDouble();

 DisplayObject hit = null;

 for (int i = _children.length - 1; i >= 0; i--) {

   var child = _children[i];
   var mask = child.mask;
   var matrix = child.transformationMatrix;

   if (child.visible && child.off == false) {

     num deltaX = localX - matrix.tx;
     num deltaY = localY - matrix.ty;
     num childX = (matrix.d * deltaX - matrix.c * deltaY) / matrix.det;
     num childY = (matrix.a * deltaY - matrix.b * deltaX) / matrix.det;
     num maskX = 0.0;
     num maskY = 0.0;

     if (mask != null) {
       if (mask.targetSpace == null) {
         maskX = childX;
         maskY = childY;
       } else if (identical(mask.targetSpace, child)) {
         maskX = childX;
         maskY = childY;
       } else if (identical(mask.targetSpace, this)) {
         maskX = localX;
         maskY = localY;
       } else {
         matrix = this.transformationMatrixTo(mask.targetSpace);
         matrix = (matrix != null) ? matrix : _identityMatrix;
         maskX = localX * matrix.a + localY * matrix.c + matrix.tx;
         maskY = localX * matrix.b + localY * matrix.d + matrix.ty;
       }
       if (mask.hitTest(maskX, maskY) == false) continue;
     }

     var displayObject = child.hitTestInput(childX, childY);
     if (displayObject == null) continue;

     if (displayObject is InteractiveObject && displayObject.mouseEnabled) {
       return _mouseChildren ? displayObject : this;
     }

     hit = this;
   }
 }

 return hit;
}

bool hitTestObject(DisplayObject other) #

inherited from DisplayObject
bool hitTestObject(DisplayObject other) {

 var stage1 = this.stage;
 var stage2 = other.stage;

 if (stage1 == null || stage2 == null || stage1 != stage2) return false;

 var rect1 = this.getBounds(stage1);
 var rect2 = other.getBounds(stage2);

 return rect1.intersects(rect2);
}

bool hitTestPoint(num x, num y, [bool shapeFlag = false]) #

inherited from DisplayObject
bool hitTestPoint(num x, num y, [bool shapeFlag = false]) {

 var stage = this.stage;
 if (stage == null) return false;

 if (shapeFlag) {
   var matrix = stage.transformationMatrixTo(this);
   if (matrix == null) return false;

   var stagePoint = new Point(x, y);
   var localPoint = matrix.transformPoint(stagePoint);

   return this.hitTestInput(localPoint.x, localPoint.y) != null;

 } else {

   var rect = this.getBounds(stage);
   return rect.contains(x, y);
 }
}

Point localToGlobal(Point localPoint) #

inherited from DisplayObject
Point localToGlobal(Point localPoint) {

 _tmpMatrix.identity();

 for(var current = this; current != null; current = current._parent) {
   _tmpMatrix.concat(current.transformationMatrix);
 }

 return _tmpMatrix.transformPoint(localPoint);
}

EventStream<Event> on(String eventType) #

inherited from EventDispatcher
EventStream<Event> on(String eventType) {

 var eventStreams = _eventStreams;
 if (eventStreams == null) {
   eventStreams = new Map<String, EventStream>();
   _eventStreams = eventStreams;
 }

 var eventStream = eventStreams[eventType];
 if (eventStream == null) {
   eventStream = new EventStream._internal(this, eventType);
   eventStreams[eventType] = eventStream;
 }

 return eventStream;
}

void refreshCache() #

inherited from DisplayObject
void refreshCache() {

 if (_cacheTexture == null) return;

 var x = _cacheRectangle.x;
 var y = _cacheRectangle.y;
 var width = _cacheRectangle.width;
 var height = _cacheRectangle.height;
 var canvas = _cacheTexture.canvas;

 var matrix = _cacheTexture.quad.drawMatrix..translate(-x, -y);
 var renderContext = new RenderContextCanvas(canvas, Color.Transparent);
 var renderState = new RenderState(renderContext, matrix);

 renderContext.clear();
 render(renderState);

 if (_filters != null) {
   var cacheBitmapData = new BitmapData.fromRenderTextureQuad(_cacheTexture.quad);
   var bounds = this.getBoundsTransformed(_identityMatrix)..offset(-x, -y);
   for(var filter in _filters) {
     var filterOverlap = filter.overlap;
     var filterBounds = bounds.clone();
     filterBounds.offset(filterOverlap.x, filterOverlap.y);
     filterBounds.inflate(filterOverlap.width, filterOverlap.height);
     filter.apply(cacheBitmapData, filterBounds.align());
   }
 }

 if (_cacheDebugBorder) {
   canvas.context2D
       ..setTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
       ..lineWidth = 1
       ..lineJoin = "miter"
       ..lineCap = "butt"
       ..strokeStyle = "#FF00FF"
       ..strokeRect(0.5, 0.5, canvas.width - 1, canvas.height - 1);
 }

 _cacheTexture.update();
}

void removeCache() #

inherited from DisplayObject
void removeCache() {
 if (_cacheTexture != null) {
   _cacheTexture.dispose();
   _cacheTexture = null;
 }
}

void removeChild(DisplayObject child) #

void removeChild(DisplayObject child) {

 int childIndex = _children.indexOf(child);
 if (childIndex == -1) {
   throw new ArgumentError(
       "Error #2025: The supplied DisplayObject must be a child of the caller.");
 }

 removeChildAt(childIndex);
}

void removeChildAt(int index) #

void removeChildAt(int index) {

 if (index < 0 || index >= _children.length) {
   throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
 }

 DisplayObject child = _children[index];

 child.dispatchEvent(new Event(Event.REMOVED, true));

 if (this.stage != null) {
   _dispatchEventDescendants(child, new Event(Event.REMOVED_FROM_STAGE));
 }

 child._parent = null;
 _children.removeAt(index);
}

void removeChildren([int beginIndex = 0, int endIndex = 0x7fffffff]) #

void removeChildren([int beginIndex = 0, int endIndex = 0x7fffffff]) {

 var length = _children.length;
 if (length == 0) return;

 if (endIndex == 0x7fffffff) {
   endIndex = length - 1;
 }

 if (beginIndex < 0 || endIndex < 0 || beginIndex >= length || endIndex >= length) {
   throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
 }

 for(int i = beginIndex; i <= endIndex; i++) {
   if (beginIndex >= _children.length) break;
   removeChildAt(beginIndex);
 }
}

void removeEventListener(String eventType, EventListener eventListener, {bool useCapture: false}) #

inherited from EventDispatcher
void removeEventListener(String eventType, EventListener eventListener, {
 bool useCapture: false }) {

 this.on(eventType)._unsubscribe(eventListener, useCapture);
}

void removeEventListeners(String eventType) #

inherited from EventDispatcher
void removeEventListeners(String eventType) {
 this.on(eventType).cancelSubscriptions();
}

void removeFromParent() #

inherited from DisplayObject
void removeFromParent() {
 if (_parent != null)
   _parent.removeChild(this);
}

void render(RenderState renderState) #

void render(RenderState renderState) {

 for(int i = 0; i < _children.length; i++) {
   DisplayObject child = _children[i];
   if (child.visible && child.off == false) {
     renderState.renderDisplayObject(child);
   }
 }
}

void setChildIndex(DisplayObject child, int index) #

void setChildIndex(DisplayObject child, int index) {

 if (index < 0 || index >= _children.length) {
   throw new ArgumentError("Error #2006: The supplied index is out of bounds.");
 }

 int oldIndex = getChildIndex(child);
 if (oldIndex == -1) {
   throw new ArgumentError("Error #2025: The supplied DisplayObject must be a child of the caller.");
 }

 _children.removeAt(oldIndex);
 _children.insert(index, child);
}

void setTransform(num x, num y, [num scaleX, num scaleY, num rotation, num skewX, num skewY, num pivotX, num pivotY]) #

inherited from DisplayObject
void setTransform(num x, num y, [num scaleX, num scaleY, num rotation, num skewX, num skewY, num pivotX, num pivotY]) {
 if (x is num) _x = x;
 if (y is num) _y = y;
 if (scaleX is num) _scaleX = scaleX;
 if (scaleY is num) _scaleY = scaleY;
 if (rotation is num) _rotation = rotation;
 if (skewX is num) _skewX = skewX;
 if (skewY is num) _skewY = skewY;
 if (pivotX is num) _pivotX = pivotX;
 if (pivotY is num) _pivotY = pivotY;
 _transformationMatrixRefresh = true;
}

void sortChildren(Function compareFunction) #

void sortChildren(Function compareFunction) {
 _children.sort(compareFunction);
}

void swapChildren(DisplayObject child1, DisplayObject child2) #

void swapChildren(DisplayObject child1, DisplayObject child2) {

 int index1 = getChildIndex(child1);
 int index2 = getChildIndex(child2);

 if (index1 == -1 || index2 == -1) {
   throw new ArgumentError("Error #2025: The supplied DisplayObject must be a child of the caller.");
 }

 swapChildrenAt(index1, index2);
}

void swapChildrenAt(int index1, int index2) #

void swapChildrenAt(int index1, int index2) {

 DisplayObject child1 = getChildAt(index1);
 DisplayObject child2 = getChildAt(index2);
 _children[index1] = child2;
 _children[index2] = child1;
}

Matrix transformationMatrixTo(DisplayObject targetSpace) #

inherited from DisplayObject
Matrix transformationMatrixTo(DisplayObject targetSpace) {

 if (targetSpace == _parent) {
   return this.transformationMatrix.clone();
 }

 if (targetSpace != null && targetSpace._parent == this) {
   return targetSpace.transformationMatrix.cloneInvert();
 }

 //------------------------------------------------

 Matrix resultMatrix = new Matrix.fromIdentity();
 DisplayObject resultObject = this;

 while(resultObject != targetSpace && resultObject._parent != null) {
   resultMatrix.concat(resultObject.transformationMatrix);
   resultObject = resultObject._parent;
 }

 if (targetSpace == null && resultObject != null) {
   resultMatrix.concat(resultObject.transformationMatrix);
   resultObject = null;
 }

 if (resultObject == targetSpace)
   return resultMatrix;

 //------------------------------------------------

 Matrix targetMatrix = new Matrix.fromIdentity();
 DisplayObject targetObject = targetSpace;

 while(targetObject != this && targetObject._parent != null) {
   targetMatrix.concat(targetObject.transformationMatrix);
   targetObject = targetObject._parent;
 }

 targetMatrix.invert();

 if (targetObject == this) {
   return targetMatrix;
 }

 if (targetObject != resultObject) {
   return null;
 }

 resultMatrix.concat(targetMatrix);

 return resultMatrix;
}