/src/away3d/library/AssetLibrary.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 233 lines · 108 code · 26 blank · 99 comment · 0 complexity · da9c05593a30a8654ed89c99f646872e MD5 · raw file

  1. package away3d.library
  2. {
  3. import away3d.arcane;
  4. import away3d.library.assets.IAsset;
  5. import away3d.library.naming.ConflictStrategyBase;
  6. import away3d.library.utils.AssetLibraryIterator;
  7. import away3d.loaders.misc.AssetLoaderContext;
  8. import away3d.loaders.misc.AssetLoaderToken;
  9. import away3d.loaders.misc.SingleFileLoader;
  10. import away3d.loaders.parsers.ParserBase;
  11. import flash.net.URLRequest;
  12. use namespace arcane;
  13. /**
  14. * AssetLibrary enforces a singleton pattern and is not intended to be instanced.
  15. * It's purpose is to allow access to the default library bundle through a set of static shortcut methods.
  16. * If you are interested in creating multiple library bundles, please use the <code>getBundle()</code> method.
  17. */
  18. public class AssetLibrary
  19. {
  20. arcane static var _instances:Object = {};
  21. /**
  22. * Creates a new <code>AssetLibrary</code> object.
  23. *
  24. * @param se A singleton enforcer for the AssetLibrary ensuring it cannnot be instanced.
  25. */
  26. public function AssetLibrary(se:AssetLibrarySingletonEnforcer)
  27. {
  28. se = se;
  29. }
  30. /**
  31. * Returns an AssetLibrary bundle instance. If no key is given, returns the default bundle (which is
  32. * similar to using the AssetLibraryBundle as a singleton). To keep several separated library bundles,
  33. * pass a string key to this method to define which bundle should be returned. This is
  34. * referred to as using the AssetLibraryBundle as a multiton.
  35. *
  36. * @param key Defines which multiton instance should be returned.
  37. * @return An instance of the asset library
  38. */
  39. public static function getBundle(key:String = 'default'):AssetLibraryBundle
  40. {
  41. return AssetLibraryBundle.getInstance(key);
  42. }
  43. /**
  44. *
  45. */
  46. public static function enableParser(parserClass:Class):void
  47. {
  48. SingleFileLoader.enableParser(parserClass);
  49. }
  50. /**
  51. *
  52. */
  53. public static function enableParsers(parserClasses:Vector.<Class>):void
  54. {
  55. SingleFileLoader.enableParsers(parserClasses);
  56. }
  57. /**
  58. * Short-hand for conflictStrategy property on default asset library bundle.
  59. *
  60. * @see away3d.library.AssetLibraryBundle.conflictStrategy
  61. */
  62. public static function get conflictStrategy():ConflictStrategyBase
  63. {
  64. return getBundle().conflictStrategy;
  65. }
  66. public static function set conflictStrategy(val:ConflictStrategyBase):void
  67. {
  68. getBundle().conflictStrategy = val;
  69. }
  70. /**
  71. * Short-hand for conflictPrecedence property on default asset library bundle.
  72. *
  73. * @see away3d.library.AssetLibraryBundle.conflictPrecedence
  74. */
  75. public static function get conflictPrecedence():String
  76. {
  77. return getBundle().conflictPrecedence;
  78. }
  79. public static function set conflictPrecedence(val:String):void
  80. {
  81. getBundle().conflictPrecedence = val;
  82. }
  83. /**
  84. * Short-hand for createIterator() method on default asset library bundle.
  85. *
  86. * @see away3d.library.AssetLibraryBundle.createIterator()
  87. */
  88. public static function createIterator(assetTypeFilter:String = null, namespaceFilter:String = null, filterFunc:Function = null):AssetLibraryIterator
  89. {
  90. return getBundle().createIterator(assetTypeFilter, namespaceFilter, filterFunc);
  91. }
  92. /**
  93. * Short-hand for load() method on default asset library bundle.
  94. *
  95. * @see away3d.library.AssetLibraryBundle.load()
  96. */
  97. public static function load(req:URLRequest, context:AssetLoaderContext = null, ns:String = null, parser:ParserBase = null):AssetLoaderToken
  98. {
  99. return getBundle().load(req, context, ns, parser);
  100. }
  101. /**
  102. * Short-hand for loadData() method on default asset library bundle.
  103. *
  104. * @see away3d.library.AssetLibraryBundle.loadData()
  105. */
  106. public static function loadData(data:*, context:AssetLoaderContext = null, ns:String = null, parser:ParserBase = null):AssetLoaderToken
  107. {
  108. return getBundle().loadData(data, context, ns, parser);
  109. }
  110. public static function stopLoad():void
  111. {
  112. getBundle().stopAllLoadingSessions();
  113. }
  114. /**
  115. * Short-hand for getAsset() method on default asset library bundle.
  116. *
  117. * @see away3d.library.AssetLibraryBundle.getAsset()
  118. */
  119. public static function getAsset(name:String, ns:String = null):IAsset
  120. {
  121. return getBundle().getAsset(name, ns);
  122. }
  123. /**
  124. * Short-hand for addEventListener() method on default asset library bundle.
  125. */
  126. public static function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
  127. {
  128. getBundle().addEventListener(type, listener, useCapture, priority, useWeakReference);
  129. }
  130. /**
  131. * Short-hand for removeEventListener() method on default asset library bundle.
  132. */
  133. public static function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
  134. {
  135. getBundle().removeEventListener(type, listener, useCapture);
  136. }
  137. /**
  138. * Short-hand for hasEventListener() method on default asset library bundle.
  139. */
  140. public static function hasEventListener(type:String):Boolean
  141. {
  142. return getBundle().hasEventListener(type);
  143. }
  144. public static function willTrigger(type:String):Boolean
  145. {
  146. return getBundle().willTrigger(type);
  147. }
  148. /**
  149. * Short-hand for addAsset() method on default asset library bundle.
  150. *
  151. * @see away3d.library.AssetLibraryBundle.addAsset()
  152. */
  153. public static function addAsset(asset:IAsset):void
  154. {
  155. getBundle().addAsset(asset);
  156. }
  157. /**
  158. * Short-hand for removeAsset() method on default asset library bundle.
  159. *
  160. * @param asset The asset which should be removed from the library.
  161. * @param dispose Defines whether the assets should also be disposed.
  162. *
  163. * @see away3d.library.AssetLibraryBundle.removeAsset()
  164. */
  165. public static function removeAsset(asset:IAsset, dispose:Boolean = true):void
  166. {
  167. getBundle().removeAsset(asset, dispose);
  168. }
  169. /**
  170. * Short-hand for removeAssetByName() method on default asset library bundle.
  171. *
  172. * @param name The name of the asset to be removed.
  173. * @param ns The namespace to which the desired asset belongs.
  174. * @param dispose Defines whether the assets should also be disposed.
  175. *
  176. * @see away3d.library.AssetLibraryBundle.removeAssetByName()
  177. */
  178. public static function removeAssetByName(name:String, ns:String = null, dispose:Boolean = true):IAsset
  179. {
  180. return getBundle().removeAssetByName(name, ns, dispose);
  181. }
  182. /**
  183. * Short-hand for removeAllAssets() method on default asset library bundle.
  184. *
  185. * @param dispose Defines whether the assets should also be disposed.
  186. *
  187. * @see away3d.library.AssetLibraryBundle.removeAllAssets()
  188. */
  189. public static function removeAllAssets(dispose:Boolean = true):void
  190. {
  191. getBundle().removeAllAssets(dispose);
  192. }
  193. /**
  194. * Short-hand for removeNamespaceAssets() method on default asset library bundle.
  195. *
  196. * @see away3d.library.AssetLibraryBundle.removeNamespaceAssets()
  197. */
  198. public static function removeNamespaceAssets(ns:String = null, dispose:Boolean = true):void
  199. {
  200. getBundle().removeNamespaceAssets(ns, dispose);
  201. }
  202. }
  203. }
  204. // singleton enforcer
  205. class AssetLibrarySingletonEnforcer
  206. {
  207. }