Created
November 6, 2015 00:47
-
-
Save mikatalk/045ef797f33c85df4ad2 to your computer and use it in GitHub Desktop.
Asset Loader Singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment