<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
viewSourceURL="srcview/index.html">
<mx:creationComplete>
<![CDATA[
initApp();
]]>
</mx:creationComplete>
<mx:Script>
<![CDATA[
import flash.utils.describeType;
import mx.controls.Alert;
private var ld:Loader;
private function initApp():void
{
ld = new Loader();
ld.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleted);
ld.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrHandler);
ld.contentLoaderInfo.addEventListener(
SecurityErrorEvent.SECURITY_ERROR,securityErrHandler);
}
private function loadSWF():void
{
var sSWF:String = txtURL.text;
var req:URLRequest = new URLRequest(sSWF);
var context:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain,null);
req.contentType = "";
ld.load(req,context);
// addChild(ld);
}
private function getDef():void
{
var cls:Class = loadClassDefinition(txtClassName.text);
if(cls){
var obj:Object = new cls();
txtDump.text = flash.utils.describeType(obj).toString();
}
}
private function loadCompleted(e:Event):void
{
Alert.show("[" + e.target.url + "] loaded");
}
private function ioErrHandler(e:IOErrorEvent):void
{
Alert.show(e.text);
}
private function securityErrHandler(e:IOErrorEvent):void
{
Alert.show(e.text);
}
private function loadClassDefinition(sClassName:String):Class
{
var cls:Class = null;
try{
cls = ld.contentLoaderInfo.applicationDomain.
getDefinition(sClassName) as Class;
return cls;
}catch(e:Error){
throw new IllegalOperationError(sClassName + " doesn't exist");
}
return cls;
}
]]>
</mx:Script>
<mx:Label text="A sample of describing class definition " fontWeight="bold" fontSize="16"/>
<mx:HRule width="100%" height="40" />
<mx:HBox width="100%">
<mx:TextInput id="txtURL" text=
"http://Shigeru-Nakagaki.com/flex_samples/ApplicationDomain/getDefinitionDump
/RunTimeClass03/RunTimeClass03.swf" width="400" />
<mx:Button x="10" y="10" label="Load SWF" click="loadSWF()"/>
</mx:HBox>
<mx:HBox width="100%">
<mx:TextInput id="txtClassName" text="org.Pepe.ExPanel" width="400" />
<mx:Button x="10" y="40" label="Get Definition" click="getDef()"/>
</mx:HBox>
<mx:HBox width="100%" height="90%">
<mx:TextArea id="txtDump" width="100%" height="100%"/>
</mx:HBox>
</mx:Application>
flex 加载 swf
最新推荐文章于 2014-11-25 11:17:01 发布