Posted By

burakkirkil on 07/29/12


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

fedecp


Simple Asset Manager with Embed Style


 / Published in: ActionScript 3
 

Simple Asset Manager with Embed Style

  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  

You need to login to post a comment.