package net.fdms.Frame 
{
	import flash.display.DisplayObject;
	/**
	 * 2011/6/8 9:42
	 * @author Dawnboy
	 */
	public class Space 
	{
		
		private static var _space:Array = [];
		public function Space() 
		{
			/*[
				[space, target];
			]*/
		}
		
		public static function addSpace(space:String,target:DisplayObject):void {
			if (checkExist(space)) {
				addToSpace(space, target);
			}else {
				_space.push([space, target]);
			}
		}
		
		public static function clearSpace(space:String):void {
			var result:Boolean = false;
			var n:int = _space.length;
			for (var a:int = 0; a < n; a++ ) {
				if (_space[a][0] == space) {
					_space[a][1] = null;
					break;
				}
			}
		}
		
		/**
		 * 查看空间是否已存在
		 * @param	space
		 * @return
		 */
		public static function checkExist(space:String):Boolean {
			var result:Boolean = false;
			var n:int = _space.length;
			for (var a:int = 0; a < n; a++ ) {
				if (_space[a][0] == space) {
					result = true;
					break;
				}
			}
			return result;
		}
		
		/**
		 * 查看空间是否为空
		 * @param	space
		 * @return
		 */
		public static function checkEmpty(space:String):Boolean {
			var result:Boolean = true;
			var n:int = _space.length;
			for (var a:int = 0; a < n; a++ ) {
				if (_space[a][0] == space && _space[a][1] != null) {
					result = false;
					break;
				}
			}
			return result;
		}
		
		/**
		 * 获取显示空间引用的对象
		 * @param	space
		 * @return
		 */
		public static function getSpaceChild(space:String):DisplayObject {
			var result:DisplayObject;
			var n:int = _space.length;
			for (var a:int = 0; a < n; a++ ) {
				if (_space[a][0] == space && _space[a][1]) {
					result = _space[a][1];
					break;
				}
			}
			return result;
			
		}
		
		/**
		 * 加入SPACE
		 * @param	space
		 */
		private static function addToSpace(space:String, target:DisplayObject):void {
			var n:int = _space.length;
			for (var a:int = 0; a < n; a++ ) {
				if (_space[a][0] == space) {
					_space[a][1] = null;
					_space[a][1] = target;
					break;
				}
			}
		}
		
	}

}