flex 加载 swf


<?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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值