Flex 加载资源、Skin 等文件,并动态生成对象

private var symbolLoader:Loader = null;
private var symbolRequest:URLRequest = null;

private function loadTeamSymbol():void{
	symbolLoader = new Loader();
	symbolLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, symbolLoader_CompleteHandler);
	symbolRequest = new URLRequest(SourceImagesPath.teamSymbolPath + "teamSymbol.swf");
	var loaderContext:LoaderContext = new LoaderContext(true);
	loaderContext.applicationDomain = ApplicationDomain.currentDomain;
	symbolLoader.load(symbolRequest, loaderContext);
}

private function symbolLoader_CompleteHandler(event:Event):void{
	//var teamSymbolClass:Class = getDefinitionByName("TeamSymbol") as Class;
	//var teamSymbolClass:Class = ApplicationDomain.currentDomain.getDefinition("TeamSymbol") as Class;
	var teamSymbolClass:Class = symbolLoader.contentLoaderInfo.applicationDomain.getDefinition("TeamSymbol") as Class;
	Cache.teamSymbol = new teamSymbolClass();
}

 

import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	import game.com.tool.MsgBox;

	public class LoadExternalRes
	{	
		private static var currObj:LoadExternalRes = new LoadExternalRes();
		
		private var externalResLoader:Loader = null;
		private var externalResRequest:URLRequest = null;
		
		public function LoadExternalRes()
		{
		}
		
		public static function instance():LoadExternalRes{
			return currObj;
		}
		
		/**
		 *加载外部资源 
		 * @param path
		 */
		public function loadExternalResources(path:String):void{
			externalResLoader = new Loader();
			externalResLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, externalResLoader_CompleteHandler);
			externalResLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, externalResLoader_IoErrorHandler);
			externalResLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, externalResLoader_SecurityErrorHandler);
			externalResRequest = new URLRequest(path);
			var loaderContext:LoaderContext = new LoaderContext(true);
			loaderContext.applicationDomain = ApplicationDomain.currentDomain;
			externalResLoader.load(externalResRequest, loaderContext);
		}
		
		private function externalResLoader_CompleteHandler(event:Event):void{
			//加载完成
		}
		
		private function externalResLoader_IoErrorHandler(event:IOErrorEvent):void{
			var loaderUrl:String = (event.currentTarget as LoaderInfo).loaderURL;
			MsgBox.newMsgBoxByContent("IoError:" + loaderUrl + "加载错误...");
		}
		
		private function externalResLoader_SecurityErrorHandler(event:SecurityErrorEvent):void{
			var loaderUrl:String = (event.currentTarget as LoaderInfo).loaderURL;
			MsgBox.newMsgBoxByContent("SecurityError:" + loaderUrl + "加载错误...");
		}
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值