Broke unloading the media out into its own method.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@696 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2008-11-12 02:48:19 +00:00
parent d7e607972d
commit e4dd02746c
+45 -39
View File
@@ -315,48 +315,25 @@ public class MediaContainer extends Sprite
*/ */
public function shutdown (completely :Boolean = true) :void public function shutdown (completely :Boolean = true) :void
{ {
try { // remove the mask (but only if we added it)
// remove the mask (but only if we added it) if (_media != null && _media.mask != null) {
if (_media != null && _media.mask != null) { try {
try { removeChild(_media.mask);
removeChild(_media.mask); _media.mask = null;
_media.mask = null;
} catch (argErr :ArgumentError) { } catch (argErr :ArgumentError) {
// If we catch this error, it was thrown in removeChild // If we catch this error, it was thrown in removeChild
// and means that we did not add the media's mask, // and means that we did not add the media's mask,
// and so shouldn't remove it either. The action we // and so shouldn't remove it either. The action we
// take here is NOT setting _media.mask = null. // take here is NOT setting _media.mask = null.
// Then, we continue happily... // Then, we continue happily...
}
} }
}
if (_media is Loader) { shutdownMedia();
var loader :Loader = (_media as Loader); if (_media != null) {
//var url :String = loader.contentLoaderInfo.url; removeChild(_media);
dispatchEvent(new Event(Event.UNLOAD));
// remove any listeners
removeListeners(loader.contentLoaderInfo);
// dispose of media
LoaderUtil.unload(loader);
dispatchEvent(new Event(Event.UNLOAD));
removeChild(loader);
//var extra :String = (url == _url) ? "" : (", _url=" + _url);
//log.debug("Unloaded media [url=" + url + extra + "].");
} else if (_media is SimpleVideoDisplay) {
var vid :SimpleVideoDisplay = SimpleVideoDisplay(_media);
// vid.removeEventListener(VideoPlayerCodes.SIZE, handleVideoSizeKnown);
vid.unload();
removeChild(vid);
} else if (_media != null) {
removeChild(_media);
}
} catch (ioe :IOError) {
log.warning("Error shutting down media", ioe);
} }
// clean everything up // clean everything up
@@ -743,6 +720,35 @@ public class MediaContainer extends Sprite
// nada // nada
} }
/**
* Do whatever is necessary to shut down the media.
*/
protected function shutdownMedia () :void
{
if (_media is Loader) {
try {
var loader :Loader = (_media as Loader);
//var url :String = loader.contentLoaderInfo.url;
// remove any listeners
removeListeners(loader.contentLoaderInfo);
// dispose of media
LoaderUtil.unload(loader);
//var extra :String = (url == _url) ? "" : (", _url=" + _url);
//log.debug("Unloaded media [url=" + url + extra + "].");
} catch (ioe :IOError) {
log.warning("Error shutting down media", ioe);
}
} else if (_media is SimpleVideoDisplay) {
var vid :SimpleVideoDisplay = SimpleVideoDisplay(_media);
// vid.removeEventListener(VideoPlayerCodes.SIZE, handleVideoSizeKnown);
vid.unload();
}
}
/** The unaltered URL of the content we're displaying. */ /** The unaltered URL of the content we're displaying. */
protected var _url :String; protected var _url :String;