Flex 리소스, Skin 등의 파일을 로드하고 객체를 동적으로 생성

3345 단어 Flex
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 + " ...");
		}
	}

좋은 웹페이지 즐겨찾기