diff --git a/src/as/com/threerings/flash/MediaContainer.as b/src/as/com/threerings/flash/MediaContainer.as index 5ebb1bf5..20da7d91 100644 --- a/src/as/com/threerings/flash/MediaContainer.as +++ b/src/as/com/threerings/flash/MediaContainer.as @@ -179,6 +179,16 @@ public class MediaContainer extends Sprite didShowNewMedia(); } + /** + * Sets whether this MediaContainer automatically shuts down when removed + * from the stage. By default this is not enabled. + */ + public function setShutdownOnRemove (enable :Boolean = true) :void + { + var fn :Function = enable ? addEventListener : removeEventListener; + fn(Event.REMOVED_FROM_STAGE, handleShutdownOnRemove); + } + /** * A place where subclasses can initialize things prior to showing new media. */ @@ -590,6 +600,15 @@ public class MediaContainer extends Sprite stoppedLoading(); } + /** + * Handle shutting us down when we're removed. Only called if + * setShutdownOnRemove() was enabled. + */ + protected function handleShutdownOnRemove (event :Event) :void + { + shutdown(); + } + /** * Configure the mask for this object. */