/ Published in: ActionScript 3
Simple Asset Manager with Embed Style
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//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 ).@name.toXMLString(); var fullname:String = className + "_" + name; var ref:Object = getDefinitionByName( fullname ); return new ref(); } } }