As pointed out, `newChild.parent` could be accessed after it was set to
undefined. This fix unifies the code from the various `destroy` methods so
the previou issue does not occur.
This commit is contained in:
Paul 2014-12-05 19:34:17 -08:00
parent e7f3b9188e
commit fe8c5021fa

View file

@ -692,24 +692,23 @@ Phaser.Group.prototype.replace = function (oldChild, newChild) {
if (index !== -1) if (index !== -1)
{ {
if (newChild.parent !== undefined) if (newChild.parent)
{ {
newChild.events.onRemovedFromGroup$dispatch(newChild, this);
newChild.parent.removeChild(newChild);
if (newChild.parent instanceof Phaser.Group) if (newChild.parent instanceof Phaser.Group)
{ {
newChild.parent.updateZ(); newChild.parent.remove(newChild);
}
else
{
newChild.parent.removeChild(newChild);
} }
} }
var temp = oldChild; this.remove(oldChild);
this.remove(temp);
this.addAt(newChild, index); this.addAt(newChild, index);
return temp; return oldChild;
} }
}; };