package net.fdms.Frame 
{
	import flash.display.Sprite;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;

	/**
	 * 框架库
	 * @author Dawnboy
	 */
	public class Frame 
	{
		
		public static var Root:Sprite;
		public static var Stage:DisplayObject;
		public static var Control:Sprite;
		private static var _framelist:Array = [];
		
		public function Frame() 
		{
			
		}
		
		/**
		 * 框架各主要层级初始化
		 * @param	root
		 * @param	stage
		 * @param	control
		 */
		public static function init(root:DisplayObject, stage:DisplayObject,control:DisplayObject):void {
			Root = root as Sprite;
			Stage = stage;
			Control = control as Sprite;
		}
		
		/**
		 * 创造容器框架
		 * @param	root	根容器
		 * @param	list	配置文档
		 */
		public static function create(root:*,list:XMLList):void {
			var n:int = list.length()-1;
			for(var a:int = n;a>=0;a--){
				var temp:Sprite = new Sprite();
				temp.name = (list[a].@id != undefined && list[a].@id != "")?list[a].@id:temp.name;
				if(list[a].children().length()){
					create(temp,list[a].children());
				}
				temp.mouseEnabled = false;
				root.addChild(temp);
				_framelist.push([temp.name, temp])
			}
			
		}
		
		/**
		 * 通过id获取显示容器
		 * @param	name
		 * @return
		 */
		public static function getContainer(name:String):DisplayObjectContainer {
			var n:int = _framelist.length;
			var result:DisplayObjectContainer;
			for (var a:int = 0; a < n; a++) {
				if (_framelist[a][0] == name) {
					result = _framelist[a][1];
					break;
				}
			}
			return result;
		}
		
		
		private static function createFrame(container:DisplayObjectContainer, list:XMLList):void {
			
			
		}
		
		
	}

}