PageRenderTime 223ms CodeModel.GetById 110ms app.highlight 6ms RepoModel.GetById 105ms app.codeStats 0ms

/src/away3d/loaders/misc/ResourceDependency.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 129 lines | 84 code | 19 blank | 26 comment | 3 complexity | f3278592c68e8b5dd53bc4025713ecda MD5 | raw file
  1package away3d.loaders.misc
  2{
  3	import away3d.arcane;
  4	import away3d.library.assets.IAsset;
  5	import away3d.loaders.parsers.ParserBase;
  6	
  7	import flash.net.URLRequest;
  8	
  9	use namespace arcane;
 10	
 11	/**
 12	 * ResourceDependency represents the data required to load, parse and resolve additional files ("dependencies")
 13	 * required by a parser, used by ResourceLoadSession.
 14	 *
 15	 */
 16	public class ResourceDependency
 17	{
 18		private var _id:String;
 19		private var _req:URLRequest;
 20		private var _assets:Vector.<IAsset>;
 21		private var _parentParser:ParserBase;
 22		private var _data:*;
 23		private var _retrieveAsRawData:Boolean;
 24		private var _suppressAssetEvents:Boolean;
 25		private var _dependencies:Vector.<ResourceDependency>;
 26		
 27		arcane var loader:SingleFileLoader;
 28		arcane var success:Boolean;
 29		
 30		public function ResourceDependency(id:String, req:URLRequest, data:*, parentParser:ParserBase, retrieveAsRawData:Boolean = false, suppressAssetEvents:Boolean = false)
 31		{
 32			_id = id;
 33			_req = req;
 34			_parentParser = parentParser;
 35			_data = data;
 36			_retrieveAsRawData = retrieveAsRawData;
 37			_suppressAssetEvents = suppressAssetEvents;
 38			
 39			_assets = new Vector.<IAsset>();
 40			_dependencies = new Vector.<ResourceDependency>();
 41		}
 42		
 43		public function get id():String
 44		{
 45			return _id;
 46		}
 47		
 48		public function get assets():Vector.<IAsset>
 49		{
 50			return _assets;
 51		}
 52		
 53		public function get dependencies():Vector.<ResourceDependency>
 54		{
 55			return _dependencies;
 56		}
 57		
 58		public function get request():URLRequest
 59		{
 60			return _req;
 61		}
 62		
 63		public function get retrieveAsRawData():Boolean
 64		{
 65			return _retrieveAsRawData;
 66		}
 67		
 68		public function get suppresAssetEvents():Boolean
 69		{
 70			return _suppressAssetEvents;
 71		}
 72		
 73		/**
 74		 * The data containing the dependency to be parsed, if the resource was already loaded.
 75		 */
 76		public function get data():*
 77		{
 78			return _data;
 79		}
 80		
 81		/**
 82		 * @private
 83		 * Method to set data after having already created the dependency object, e.g. after load.
 84		 */
 85		arcane function setData(data:*):void
 86		{
 87			_data = data;
 88		}
 89		
 90		/**
 91		 * The parser which is dependent on this ResourceDependency object.
 92		 */
 93		public function get parentParser():ParserBase
 94		{
 95			return _parentParser;
 96		}
 97		
 98		/**
 99		 * Resolve the dependency when it's loaded with the parent parser. For example, a dependency containing an
100		 * ImageResource would be assigned to a Mesh instance as a BitmapMaterial, a scene graph object would be added
101		 * to its intended parent. The dependency should be a member of the dependencies property.
102		 */
103		public function resolve():void
104		{
105			if (_parentParser)
106				_parentParser.resolveDependency(this);
107		}
108		
109		/**
110		 * Resolve a dependency failure. For example, map loading failure from a 3d file
111		 */
112		public function resolveFailure():void
113		{
114			if (_parentParser)
115				_parentParser.resolveDependencyFailure(this);
116		}
117		
118		/**
119		 * Resolve the dependencies name
120		 */
121		public function resolveName(asset:IAsset):String
122		{
123			if (_parentParser)
124				return _parentParser.resolveDependencyName(this, asset);
125			return asset.name;
126		}
127	
128	}
129}