diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 92ae06e..72bf755 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -146,7 +146,7 @@ } else { - throw new Error('The supplied DisplayObjects must be a child of the caller ' + this); + throw new Error('Supplied index does not exist in the child list, or the supplied DisplayObject must be a child of the caller'); } }; @@ -158,39 +158,56 @@ */ PIXI.DisplayObjectContainer.prototype.removeChild = function(child) { - var index = this.children.indexOf( child ); - if ( index !== -1 ) - { - // update the stage reference.. - if(this.stage)child.removeStageReference(); + return this.removeChildAt( this.children.indexOf( child ) ); +}; - child.parent = undefined; - this.children.splice( index, 1 ); +/** + * Removes a child from the specified index position in the child list of the container. + * + * @method removeChildAt + * @param index {Number} The index to get the child from + */ +PIXI.DisplayObjectContainer.prototype.removeChildAt = function(index) +{ + var child = this.getChildAt( index ); + if(this.stage) + child.removeStageReference(); + + child.parent = undefined; + this.children.splice( index, 1 ); + return child; +}; + +/** +* Removes all child instances from the child list of the container. +* +* @method removeChildren +* @param beginIndex {Number} The beginning position. Predefined value is 0. +* @param endIndex {Number} The ending position. Predefined value is children's array length. +*/ +PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endIndex) +{ + var begin = beginIndex || 0; + var end = endIndex || this.children.length; + var range = end - begin; + + if (range > 0 && range <= end) + { + var removed = this.children.splice(begin, range); + for (var i = 0; i < removed.length; i++) { + var child = removed[i]; + if(this.stage) + child.removeStageReference(); + child.parent = undefined; + } + return removed; } else { - throw new Error(child + ' The supplied DisplayObject must be a child of the caller ' + this); + throw new Error( 'Range Error, numeric values are outside the acceptable range' ); } }; - -/** -* Removes all the children -* -* @method removeAll -* NOT tested yet -*/ -/* PIXI.DisplayObjectContainer.prototype.removeAll = function() -{ - - - for(var i = 0 , j = this.children.length; i < j; i++) - { - this.removeChild(this.children[i]); - } - -}; -*/ /* * Updates the container's childrens transform for rendering *