package com.samere { import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IOErrorEvent; import flash.events.ProgressEvent; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext; public class Skin extends EventDispatcher { private static var instance:Skin; private var loader:Loader; private var applicationDomain:ApplicationDomain; public function Skin(pvt:Enforcer) { loader = new Loader(); loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent):void{ dispatchEvent(event); }); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event):void{ applicationDomain = loader.content.loaderInfo.applicationDomain; dispatchEvent(event); }); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void{ dispatchEvent(event); }); } public static function getInstance():Skin { if ( instance === null ) instance = new Skin(new Enforcer); return instance; } public static function load(theme:String, systemPath:String):void { if ( instance === null ) instance = new Skin(new Enforcer); instance.loader.load(new URLRequest(systemPath+theme+".swf")); } public static function getSprite(ref:String):Sprite { trace("[Skin] ~", ref); return new (getInstance().applicationDomain.getDefinition(ref) as Class); } } } class Enforcer {}