Newer
Older
exporter / Packer / GraphicDefClipCollection.as
package  Packer {
	
	import djarts.core.CacheManager;
	import djarts.core.*;
	import djarts.display.*;
	
	public class GraphicDefClipCollection
	{

		public var ClipsLoaded = null;
		public function GraphicDefClipCollection(graphicDefs:Array = null, callback = null)
		{
			if (graphicDefs != null) LoadDefs(graphicDefs, callback);
		}
		
		var defs = null;
		public function LoadDefs(graphicDefs:Array, callback)
		{
			defs = graphicDefs;
			ClipsLoaded = callback;
			LoadNextDef();
		}
		
		public function LoadNextDef()
		{	
			if (defs.length == 0)
			{
				Done();
				return;
			}
		
			var currentDef = defs.shift();
			var g = GraphicFactory.Instance().GetGraphicByID(currentDef.ID, null, GraphicLoaded);
			if (GraphicFactory.Instance().LoadedOK(g))
			{
				GraphicLoaded(null, g);
			}
		}
		
		var clips = new Array();
		protected function GraphicLoaded(caller, g)
		{
			clips.push(g);
			LoadNextDef();
		}
		
		protected function Done()
		{
			if (ClipsLoaded != null) ClipsLoaded(clips);
		}

	}
	
}