PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

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