Simple Asset Manager with Embed Style


/ Published in: ActionScript 3
Save to your folder(s)

Simple Asset Manager with Embed Style


Copy this code and paste it in your HTML
  1. //AssetManager.as
  2. // usage: AssetManager.getInstance.getAssetByName("MonaLisa");
  3. package
  4. {
  5. import flash.utils.describeType;
  6. import flash.utils.getDefinitionByName;
  7.  
  8. public class AssetManager
  9. {
  10.  
  11. [ Embed( source="/../assets/fonts/American Typewriter.ttf",
  12. fontName="AmericanT",
  13. mimeType="application/x-font-truetype" ) ]
  14. public static const FONT_AMERICA_T:String;
  15.  
  16. [ Embed( source="/../assets/library.swf", symbol="Square") ];
  17. private var Square:Class;
  18.  
  19. [ Embed (source="/../assets/Mona_Lisa.jpg") ]
  20. private var MonaLisa:Class;
  21.  
  22. private static var instance:AssetManager;
  23.  
  24. public static function getInstance():AssetManager
  25. {
  26. if (instance == null)
  27. instance = new AssetManager();
  28. return instance;
  29. }
  30.  
  31. public function getAssetByName( name:String ):*
  32. {
  33. var className:String = describeType( this ).@name.toXMLString();
  34. var fullname:String = className + "_" + name;
  35. var ref:Object = getDefinitionByName( fullname );
  36. return new ref();
  37. }
  38.  
  39. }
  40. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.