From 330a99f3376b4cd759a0fee116eab1c1a9521331 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 2 May 2007 00:10:00 +0000 Subject: [PATCH] Added isContentInitialized(), which should be used to help differentiate between an MsoySprite that does not have any WhirledControl subclass in it and those that do, but are just not yet fully loaded. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@219 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flash/MediaContainer.as | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/as/com/threerings/flash/MediaContainer.as b/src/as/com/threerings/flash/MediaContainer.as index 487b2cdc..cf0a4142 100644 --- a/src/as/com/threerings/flash/MediaContainer.as +++ b/src/as/com/threerings/flash/MediaContainer.as @@ -94,6 +94,16 @@ public class MediaContainer extends Sprite mouseChildren = true; } + /** + * Return true if the content has been initialized. + * For most content, this is true if the media is non-null, but + * for anything loaded with a Loader, it is only true after the INIT event is dispatched. + */ + public function isContentInitialized () :Boolean + { + return (_media != null) && (_initialized || !(_media is Loader)); + } + /** * Get the media. If the media was loaded using a URL, this will * likely be the Loader object holding the real media. @@ -158,7 +168,7 @@ public class MediaContainer extends Sprite */ protected function willShowNewMedia () :void { - // nada in here + _initialized = false; } /** @@ -186,6 +196,7 @@ public class MediaContainer extends Sprite _media = loader; var info :LoaderInfo = loader.contentLoaderInfo; info.addEventListener(Event.COMPLETE, loadingComplete); + info.addEventListener(Event.INIT, handleInit); info.addEventListener(IOErrorEvent.IO_ERROR, loadError); info.addEventListener(ProgressEvent.PROGRESS, loadProgress); @@ -398,6 +409,7 @@ public class MediaContainer extends Sprite protected function removeListeners (info :LoaderInfo) :void { info.removeEventListener(Event.COMPLETE, loadingComplete); + info.removeEventListener(Event.INIT, handleInit); info.removeEventListener(IOErrorEvent.IO_ERROR, loadError); info.removeEventListener(ProgressEvent.PROGRESS, loadProgress); } @@ -445,6 +457,14 @@ public class MediaContainer extends Sprite setupBrokenImage(-1, -1); } + /** + * Handles the INIT event for content loaded with a Loader. + */ + protected function handleInit (event :Event) :void + { + _initialized = true; + } + /** * Callback function to receive COMPLETE events for swfs or images. */ @@ -560,5 +580,8 @@ public class MediaContainer extends Sprite /** Either a Loader or a VideoDisplay. */ protected var _media :DisplayObject; + + /** If we're using a Loader, true once the INIT property has been dispatched. */ + protected var _initialized :Boolean; } }