Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Event.ADDED and Event.REMOVED are now bubbling

  • Loading branch information...
commit d47ab76f80e8c5b837c42122fd6c2dbb6eeb99f8 1 parent 72dd737
@PrimaryFeather PrimaryFeather authored
View
4 starling/src/starling/display/DisplayObjectContainer.as
@@ -98,7 +98,7 @@ package starling.display
child.removeFromParent();
mChildren.splice(index, 0, child);
child.setParent(this);
- child.dispatchEvent(new Event(Event.ADDED));
+ child.dispatchEvent(new Event(Event.ADDED, true));
if (stage) child.dispatchEventOnChildren(new Event(Event.ADDED_TO_STAGE));
}
else
@@ -122,7 +122,7 @@ package starling.display
if (index >= 0 && index < numChildren)
{
var child:DisplayObject = mChildren[index];
- child.dispatchEvent(new Event(Event.REMOVED));
+ child.dispatchEvent(new Event(Event.REMOVED, true));
if (stage) child.dispatchEventOnChildren(new Event(Event.REMOVED_FROM_STAGE));
child.setParent(null);
mChildren.splice(index, 1);
View
23 tests/src/tests/DisplayObjectContainerTest.as
@@ -28,13 +28,16 @@ package tests
private var mAdded:int;
private var mAddedToStage:int;
+ private var mAddedChild:int;
private var mRemoved:int;
private var mRemovedFromStage:int;
+ private var mRemovedChild:int;
[Before]
public function setUp():void
{
- mAdded = mAddedToStage = mRemoved = mRemovedFromStage = 0;
+ mAdded = mAddedToStage = mAddedChild =
+ mRemoved = mRemovedFromStage = mRemovedChild = 0;
}
[After]
@@ -358,29 +361,40 @@ package tests
quad.addEventListener(Event.REMOVED, onRemoved);
quad.addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
+ stage.addEventListener(Event.ADDED, onAddedChild);
+ stage.addEventListener(Event.REMOVED, onRemovedChild);
+
sprite.addChild(quad);
Assert.assertEquals(1, mAdded);
Assert.assertEquals(0, mRemoved);
Assert.assertEquals(0, mAddedToStage);
Assert.assertEquals(0, mRemovedFromStage);
+ Assert.assertEquals(0, mAddedChild);
+ Assert.assertEquals(0, mRemovedChild);
stage.addChild(sprite);
Assert.assertEquals(1, mAdded);
Assert.assertEquals(0, mRemoved);
Assert.assertEquals(1, mAddedToStage);
Assert.assertEquals(0, mRemovedFromStage);
+ Assert.assertEquals(1, mAddedChild);
+ Assert.assertEquals(0, mRemovedChild);
stage.removeChild(sprite);
Assert.assertEquals(1, mAdded);
Assert.assertEquals(0, mRemoved);
Assert.assertEquals(1, mAddedToStage);
Assert.assertEquals(1, mRemovedFromStage);
+ Assert.assertEquals(1, mAddedChild);
+ Assert.assertEquals(1, mRemovedChild);
sprite.removeChild(quad);
Assert.assertEquals(1, mAdded);
Assert.assertEquals(1, mRemoved);
Assert.assertEquals(1, mAddedToStage);
Assert.assertEquals(1, mRemovedFromStage);
+ Assert.assertEquals(1, mAddedChild);
+ Assert.assertEquals(1, mRemovedChild);
}
[Test]
@@ -402,8 +416,11 @@ package tests
}
private function onAdded(event:Event):void { mAdded++; }
- private function onRemoved(event:Event):void { mRemoved++; }
private function onAddedToStage(event:Event):void { mAddedToStage++; }
- private function onRemovedFromStage(event:Event):void { mRemovedFromStage++; }
+ private function onAddedChild(event:Event):void { mAddedChild++; }
+
+ private function onRemoved(event:Event):void { mRemoved++; }
+ private function onRemovedFromStage(event:Event):void { mRemovedFromStage++; }
+ private function onRemovedChild(event:Event):void { mRemovedChild++; }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.