Added getContent() to get the top-level DisplayObject from a loaded SWF.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4587 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,12 +1,17 @@
|
|||||||
package com.threerings.util {
|
package com.threerings.util {
|
||||||
|
|
||||||
|
import flash.display.DisplayObject;
|
||||||
import flash.display.Loader;
|
import flash.display.Loader;
|
||||||
import flash.display.LoaderInfo;
|
import flash.display.LoaderInfo;
|
||||||
|
|
||||||
import flash.errors.IllegalOperationError;
|
import flash.errors.IllegalOperationError;
|
||||||
|
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import flash.events.EventDispatcher;
|
import flash.events.EventDispatcher;
|
||||||
import flash.events.IOErrorEvent;
|
import flash.events.IOErrorEvent;
|
||||||
|
|
||||||
import flash.utils.ByteArray;
|
import flash.utils.ByteArray;
|
||||||
|
|
||||||
import flash.system.ApplicationDomain;
|
import flash.system.ApplicationDomain;
|
||||||
import flash.system.LoaderContext;
|
import flash.system.LoaderContext;
|
||||||
|
|
||||||
@@ -44,6 +49,15 @@ public class EmbeddedSwfLoader extends EventDispatcher
|
|||||||
_loader.loadBytes(byteArray, context);
|
_loader.loadBytes(byteArray, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the top-level display object defined in the loaded SWF.
|
||||||
|
*/
|
||||||
|
public function getContent () :DisplayObject
|
||||||
|
{
|
||||||
|
checkLoaded();
|
||||||
|
return _loader.content;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a class definition from the loaded swf.
|
* Retrieves a class definition from the loaded swf.
|
||||||
*
|
*
|
||||||
@@ -74,9 +88,7 @@ public class EmbeddedSwfLoader extends EventDispatcher
|
|||||||
*/
|
*/
|
||||||
public function getSymbol (symbolName :String) :Object
|
public function getSymbol (symbolName :String) :Object
|
||||||
{
|
{
|
||||||
if (!checkLoaded()) {
|
checkLoaded();
|
||||||
throw new IllegalOperationError("SWF has not completed loading");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
return _loader.contentLoaderInfo.applicationDomain.getDefinition(symbolName);
|
return _loader.contentLoaderInfo.applicationDomain.getDefinition(symbolName);
|
||||||
} catch (e: Error) {
|
} catch (e: Error) {
|
||||||
@@ -92,19 +104,20 @@ public class EmbeddedSwfLoader extends EventDispatcher
|
|||||||
*/
|
*/
|
||||||
public function isSymbol (className :String) :Boolean
|
public function isSymbol (className :String) :Boolean
|
||||||
{
|
{
|
||||||
if (!checkLoaded()) {
|
checkLoaded();
|
||||||
throw new IllegalOperationError("SWF has not completed loading");
|
|
||||||
}
|
|
||||||
return _loader.contentLoaderInfo.applicationDomain.hasDefinition(className);
|
return _loader.contentLoaderInfo.applicationDomain.hasDefinition(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if we've completed loaded the swf.
|
* Validate that the load operation is complete.
|
||||||
*/
|
*/
|
||||||
protected function checkLoaded () :Boolean
|
protected function checkLoaded () :void
|
||||||
{
|
{
|
||||||
var loaderInfo :LoaderInfo = _loader.contentLoaderInfo;
|
var loaderInfo :LoaderInfo = _loader.contentLoaderInfo;
|
||||||
return !(loaderInfo.bytesTotal == 0 || loaderInfo.bytesLoaded != loaderInfo.bytesTotal);
|
if (loaderInfo.bytesTotal == 0 || loaderInfo.bytesLoaded != loaderInfo.bytesTotal) {
|
||||||
|
|
||||||
|
throw new IllegalOperationError("SWF has not completed loading");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected var _loader :Loader;
|
protected var _loader :Loader;
|
||||||
|
|||||||
Reference in New Issue
Block a user