Created listener interfaces that will automatically be registered
if implemented by something on the display hierarchy. You may also implement them in utility classes and register and unregister event listening by hand. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@55 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -38,6 +38,7 @@ public class EZGamePanel extends VBox
|
||||
|
||||
// add a listener so that we hear about all new children
|
||||
addEventListener(Event.ADDED, childAdded);
|
||||
addEventListener(Event.REMOVED, childRemoved);
|
||||
|
||||
var cfg :EZGameConfig = (ctrl.getPlaceConfig() as EZGameConfig);
|
||||
_gameView = new MediaContainer(cfg.configData); // TODO
|
||||
@@ -64,6 +65,7 @@ public class EZGamePanel extends VBox
|
||||
// from PlaceView
|
||||
public function didLeavePlace (plobj :PlaceObject) :void
|
||||
{
|
||||
removeListeners(_gameView);
|
||||
_ezObj = null;
|
||||
}
|
||||
|
||||
@@ -77,6 +79,17 @@ public class EZGamePanel extends VBox
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle REMOVED events.
|
||||
*/
|
||||
protected function childRemoved (event :Event) :void
|
||||
{
|
||||
trace("Child removed: " + event.target);
|
||||
if (_ezObj != null) {
|
||||
removeListeners(event.target as DisplayObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find any children of the specified object that implement
|
||||
* com.metasoy.game.Game and provide them with the GameObject.
|
||||
@@ -93,6 +106,17 @@ public class EZGamePanel extends VBox
|
||||
_seenGames[disp] = true;
|
||||
}
|
||||
}
|
||||
// always check to see if it's a listener
|
||||
_ctrl.gameObjImpl.registerListener(disp);
|
||||
});
|
||||
}
|
||||
|
||||
protected function removeListeners (root :DisplayObject) :void
|
||||
{
|
||||
DisplayUtil.walkDisplayObjects(root,
|
||||
function (disp :DisplayObject) :void
|
||||
{
|
||||
_ctrl.gameObjImpl.unregisterListener(disp);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user