package CharacterExport
{
	import flash.display.MovieClip;
	import djarts.utils.CountWaiter;

	public class AnimationPieceSet
	{
		public var Name:String;
		public var Pieces:Array = new Array();
		
		private var waiter:CountWaiter;
		public function LoadClip(clip:MovieClip, doneCallback)
		{
			waiter = new CountWaiter(function(cw) {if (doneCallback != null) doneCallback();});
			for (var i = 0; i < clip.numChildren; i++)
			{
				var c = clip.getChildAt(i);
				if (c is MovieClip)
				{
					var child:MovieClip = c as MovieClip;
					var m;
					if (m = child.name.match("^piece_(.*)_clip$"))
					{
						
						//var index = Number(m[1]);
						var found = false;
						for (var j in Pieces)
						{
							if (Pieces[j].Key == m[1])
							{
								found = true;
								break;
							}
						}
						if (!found)
						{
							waiter.Wait();
							Pieces.push(new AnimationPiece(m[1], child, waiter.WaitDone));
						}
					}
				}
			}
			waiter.Go();
		}			
	}
}