diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d037edd..039e124 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -95,6 +95,13 @@ }); /** + * Overridable method that can be used by Container subclasses whenever the children array is modified + * + * @private + */ +Container.prototype.onChildrenChange = function () {}; + +/** * Adds a child to the container. * * @param child {DisplayObject} The DisplayObject to add to the container @@ -130,6 +137,7 @@ child.parent = this; this.children.splice(index, 0, child); + this.onChildrenChange(); child.emit('added', this); @@ -164,6 +172,7 @@ this.children[index1] = child2; this.children[index2] = child; + this.onChildrenChange(); }; /** @@ -201,6 +210,7 @@ this.children.splice(currentIndex, 1); //remove from old position this.children.splice(index, 0, child); //add at new position + this.onChildrenChange(); }; /** @@ -249,6 +259,7 @@ child.parent = null; this.children.splice(index, 1); + this.onChildrenChange(); child.emit('removed', this); @@ -276,6 +287,13 @@ removed[i].parent = null; } + this.onChildrenChange(); + + for (var i = 0; i < removed.length; ++i) + { + removed[i].emit('removed', this); + } + return removed; } else if (range === 0 && this.children.length === 0) diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d037edd..039e124 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -95,6 +95,13 @@ }); /** + * Overridable method that can be used by Container subclasses whenever the children array is modified + * + * @private + */ +Container.prototype.onChildrenChange = function () {}; + +/** * Adds a child to the container. * * @param child {DisplayObject} The DisplayObject to add to the container @@ -130,6 +137,7 @@ child.parent = this; this.children.splice(index, 0, child); + this.onChildrenChange(); child.emit('added', this); @@ -164,6 +172,7 @@ this.children[index1] = child2; this.children[index2] = child; + this.onChildrenChange(); }; /** @@ -201,6 +210,7 @@ this.children.splice(currentIndex, 1); //remove from old position this.children.splice(index, 0, child); //add at new position + this.onChildrenChange(); }; /** @@ -249,6 +259,7 @@ child.parent = null; this.children.splice(index, 1); + this.onChildrenChange(); child.emit('removed', this); @@ -276,6 +287,13 @@ removed[i].parent = null; } + this.onChildrenChange(); + + for (var i = 0; i < removed.length; ++i) + { + removed[i].emit('removed', this); + } + return removed; } else if (range === 0 && this.children.length === 0) diff --git a/src/core/particles/ParticleContainer.js b/src/core/particles/ParticleContainer.js index 4c23040..784bc25 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -161,57 +161,14 @@ }; /** - * Adds a child to this particle container at a specified index. If the index is out of bounds an error will be thrown + * Set the flag that static data should be updated to true * - * @param child {DisplayObject} The child to add - * @param index {Number} The index to place the child in - * @return {DisplayObject} The child that was added. + * @private */ -ParticleContainer.prototype.addChildAt = function (child, index) +ParticleContainer.prototype.onChildrenChange = function () { - // prevent adding self as child - if (child === this) - { - return child; - } - - if (index >= 0 && index <= this.children.length) - { - if (child.parent) - { - child.parent.removeChild(child); - } - - child.parent = this; - - this.children.splice(index, 0, child); - - this._updateStatic = true; - - return child; - } - else - { - throw new Error(child + 'addChildAt: The index '+ index +' supplied is out of bounds ' + this.children.length); - } -}; - -/** - * Removes a child from the specified index position. - * - * @param index {Number} The index to get the child from - * @return {DisplayObject} The child that was removed. - */ -ParticleContainer.prototype.removeChildAt = function (index) -{ - var child = this.getChildAt(index); - - child.parent = null; - this.children.splice(index, 1); this._updateStatic = true; - - return child; -}; +} /** * Renders the object using the Canvas renderer