Created
July 21, 2013 06:41
-
-
Save RKAN/6047739 to your computer and use it in GitHub Desktop.
Simple Asset Manager with Embed Style
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
//AssetManager.as | |
// usage: AssetManager.getInstance.getAssetByName("MonaLisa"); | |
package | |
{ | |
import flash.utils.describeType; | |
import flash.utils.getDefinitionByName; | |
public class AssetManager | |
{ | |
[ Embed( source="/../assets/fonts/American Typewriter.ttf", | |
fontName="AmericanT", | |
mimeType="application/x-font-truetype" ) ] | |
public static const FONT_AMERICA_T:String; | |
[ Embed( source="/../assets/library.swf", symbol="Square") ]; | |
private var Square:Class; | |
[ Embed (source="/../assets/Mona_Lisa.jpg") ] | |
private var MonaLisa:Class; | |
private static var instance:AssetManager; | |
public static function getInstance():AssetManager | |
{ | |
if (instance == null) | |
instance = new AssetManager(); | |
return instance; | |
} | |
public function getAssetByName( name:String ):* | |
{ | |
var className:String = describeType( this )[email protected](); | |
var fullname:String = className + "_" + name; | |
var ref:Object = getDefinitionByName( fullname ); | |
return new ref(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment