Convert MediaContainer to be just a subclass of Sprite, so that I can

de-flex the 'world' portions of metasoy.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4506 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2007-01-18 00:36:27 +00:00
parent ec54654354
commit d10b94df85
+58 -88
View File
@@ -6,6 +6,7 @@ import flash.display.DisplayObjectContainer;
import flash.display.Loader; import flash.display.Loader;
import flash.display.LoaderInfo; import flash.display.LoaderInfo;
import flash.display.Shape; import flash.display.Shape;
import flash.display.Sprite;
import flash.errors.IOError; import flash.errors.IOError;
@@ -30,14 +31,6 @@ import flash.system.SecurityDomain;
import flash.net.URLRequest; import flash.net.URLRequest;
import mx.core.ScrollPolicy;
import mx.core.UIComponent;
import mx.containers.Box;
import mx.controls.VideoDisplay;
import mx.events.VideoEvent;
import com.threerings.util.StringUtil; import com.threerings.util.StringUtil;
import com.threerings.media.image.ImageUtil; import com.threerings.media.image.ImageUtil;
@@ -46,7 +39,7 @@ import com.threerings.media.image.ImageUtil;
* A wrapper class for all media that will be placed on the screen. * A wrapper class for all media that will be placed on the screen.
* Subject to change. * Subject to change.
*/ */
public class MediaContainer extends Box public class MediaContainer extends Sprite
{ {
/** An event we dispatch when our size is known. */ /** An event we dispatch when our size is known. */
public static const SIZE_KNOWN :String = "mediaSizeKnown"; public static const SIZE_KNOWN :String = "mediaSizeKnown";
@@ -65,8 +58,6 @@ public class MediaContainer extends Box
mouseEnabled = false; mouseEnabled = false;
mouseChildren = true; mouseChildren = true;
verticalScrollPolicy = ScrollPolicy.OFF;
horizontalScrollPolicy = ScrollPolicy.OFF;
} }
/** /**
@@ -120,11 +111,7 @@ public class MediaContainer extends Box
shutdown(false); shutdown(false);
} }
if (disp is UIComponent) { addChild(disp);
addChild(disp);
} else {
rawChildren.addChild(disp);
}
_media = disp; _media = disp;
updateContentDimensions(disp.width, disp.height); updateContentDimensions(disp.width, disp.height);
} }
@@ -134,17 +121,17 @@ public class MediaContainer extends Box
*/ */
protected function setupVideo (url :String) :void protected function setupVideo (url :String) :void
{ {
var vid :VideoDisplay = new VideoDisplay(); // var vid :VideoDisplay = new VideoDisplay();
vid.autoPlay = false; // vid.autoPlay = false;
_media = vid; // _media = vid;
addChild(vid); // addChild(vid);
vid.addEventListener(ProgressEvent.PROGRESS, loadVideoProgress); // vid.addEventListener(ProgressEvent.PROGRESS, loadVideoProgress);
vid.addEventListener(VideoEvent.READY, loadVideoReady); // vid.addEventListener(VideoEvent.READY, loadVideoReady);
vid.addEventListener(VideoEvent.REWIND, videoDidRewind); // vid.addEventListener(VideoEvent.REWIND, videoDidRewind);
//
// start it loading // // start it loading
vid.source = url; // vid.source = url;
vid.load(); // vid.load();
} }
/** /**
@@ -168,7 +155,7 @@ public class MediaContainer extends Box
// start it loading, add it as a child // start it loading, add it as a child
loader.load(new URLRequest(url), getContext(url)); loader.load(new URLRequest(url), getContext(url));
rawChildren.addChild(loader); addChild(loader);
try { try {
updateContentDimensions(info.width, info.height); updateContentDimensions(info.width, info.height);
@@ -215,7 +202,7 @@ public class MediaContainer extends Box
try { try {
// remove the mask // remove the mask
if (_media != null && _media.mask != null) { if (_media != null && _media.mask != null) {
rawChildren.removeChild(_media.mask); removeChild(_media.mask);
_media.mask = null; _media.mask = null;
} }
@@ -232,34 +219,30 @@ public class MediaContainer extends Box
} }
loader.unload(); loader.unload();
rawChildren.removeChild(loader); removeChild(loader);
} else if (_media is VideoDisplay) { // } else if (_media is VideoDisplay) {
var vid :VideoDisplay = (_media as VideoDisplay); // var vid :VideoDisplay = (_media as VideoDisplay);
// remove any listeners // // remove any listeners
vid.removeEventListener(ProgressEvent.PROGRESS, // vid.removeEventListener(ProgressEvent.PROGRESS,
loadVideoProgress); // loadVideoProgress);
vid.removeEventListener(VideoEvent.READY, loadVideoReady); // vid.removeEventListener(VideoEvent.READY, loadVideoReady);
vid.removeEventListener(VideoEvent.REWIND, videoDidRewind); // vid.removeEventListener(VideoEvent.REWIND, videoDidRewind);
//
// dispose of media // // dispose of media
vid.pause(); // vid.pause();
try { // try {
vid.close(); // vid.close();
} catch (ioe :IOError) { // } catch (ioe :IOError) {
// ignore // // ignore
} // }
vid.stop(); // vid.stop();
//
// remove from hierarchy // // remove from hierarchy
removeChild(vid); // removeChild(vid);
} else if (_media != null) { } else if (_media != null) {
if (_media is UIComponent) { removeChild(_media);
removeChild(_media);
} else {
rawChildren.removeChild(_media);
}
} }
} catch (ioe :IOError) { } catch (ioe :IOError) {
log.warning("Error shutting down media: " + ioe); log.warning("Error shutting down media: " + ioe);
@@ -393,27 +376,27 @@ public class MediaContainer extends Box
*/ */
protected function loadVideoProgress (event :ProgressEvent) :void protected function loadVideoProgress (event :ProgressEvent) :void
{ {
var vid :VideoDisplay = (event.currentTarget as VideoDisplay); // var vid :VideoDisplay = (event.currentTarget as VideoDisplay);
updateContentDimensions(vid.videoWidth, vid.videoHeight); // updateContentDimensions(vid.videoWidth, vid.videoHeight);
//
updateLoadingProgress(vid.bytesLoaded, vid.bytesTotal); // updateLoadingProgress(vid.bytesLoaded, vid.bytesTotal);
} }
/** /**
* A callback to receive READY events for video. * A callback to receive READY events for video.
*/ */
protected function loadVideoReady (event :VideoEvent) :void // protected function loadVideoReady (event :VideoEvent) :void
{ // {
var vid :VideoDisplay = (event.currentTarget as VideoDisplay); // var vid :VideoDisplay = (event.currentTarget as VideoDisplay);
updateContentDimensions(vid.videoWidth, vid.videoHeight); // updateContentDimensions(vid.videoWidth, vid.videoHeight);
updateLoadingProgress(1, 1); // updateLoadingProgress(1, 1);
//
vid.play(); // vid.play();
//
// remove the two listeners // // remove the two listeners
vid.removeEventListener(ProgressEvent.PROGRESS, loadVideoProgress); // vid.removeEventListener(ProgressEvent.PROGRESS, loadVideoProgress);
vid.removeEventListener(VideoEvent.READY, loadVideoReady); // vid.removeEventListener(VideoEvent.READY, loadVideoReady);
} // }
/** /**
* Callback function to receive COMPLETE events for swfs or images. * Callback function to receive COMPLETE events for swfs or images.
@@ -430,28 +413,15 @@ public class MediaContainer extends Box
updateContentDimensions(info.width, info.height); updateContentDimensions(info.width, info.height);
updateLoadingProgress(1, 1); updateLoadingProgress(1, 1);
// // Bitmap smoothing
// if (_media is Loader) {
// var l :Loader = Loader(_media);
// try {
// if (l.content is Bitmap) {
// Bitmap(l.content).smoothing = true;
// trace("--- made bitmap smooth");
// }
// } catch (er :Error) {
// trace("--- error bitmap smooth");
// }
// }
} }
/** /**
* Called when the video auto-rewinds. * Called when the video auto-rewinds.
*/ */
protected function videoDidRewind (event :VideoEvent) :void // protected function videoDidRewind (event :VideoEvent) :void
{ // {
(_media as VideoDisplay).play(); // (_media as VideoDisplay).play();
} // }
/** /**
* Configure the mask for this object. * Configure the mask for this object.
@@ -465,7 +435,7 @@ public class MediaContainer extends Box
} else { } else {
mask = new Shape(); mask = new Shape();
// the mask must be added to the display list (which is wacky) // the mask must be added to the display list (which is wacky)
rawChildren.addChild(mask); addChild(mask);
_media.mask = mask; _media.mask = mask;
} }