package net.fdms.Resource 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import net.fdms.Frame.Frame;
	import net.fdms.Function.Convert.ResXMLtoOBJECT;
	import net.fdms.Function.Convert.XMLtoOBJECT;
	import net.fdms.Database.SysData;
	import net.fdms.Function.Loader.Loader;
	/**
	 * 2011/5/27 10:50
	 * @author Dawnboy
	 */
	public class AnalysisRes 
	{
		
		public function AnalysisRes() 
		{
			
		}
		
		public static function init():void {
			Frame.Control.addEventListener("COMPLETE", setFrame);
			if (SysData.Param.page) {
				SysData.Param.page = SysData.Param.page.split(":")
			}
			//自定义进度条初始化
			if (SysData.ResSets.progressBar != XMLList(undefined) && SysData.ResSets.progressBar.@src != "") {
				ProgressBar.Init(Frame.Control, ResXMLtoOBJECT.convert(SysData.ResSets.progressBar),Frame.Control);
			}else {
				setFrame();
			}
			
			//生成整体框架
			
		}
		
		public static function setFrame(...arg):void {
			Frame.Control.removeEventListener("COMPLETE",setFrame);
			if (SysData.ResSets.resource != undefined) {
				Frame.create(Frame.Root, SysData.ResSets.resource);
				
				addResData(SysData.ResSets.resource);
			}
			//trace(Resource.getPreloadChild("test2"));
			
			var preLoads:Array = Resource.getPreloadRes();
			if (preLoads) {
				var n:int = preLoads.length;
				for (var a:int = 0; a < n; a++ ) {
					Loader.addLoad(preLoads[a].toString());
				}
				if (SysData.Param.page) {
					Loader.removeSpaceLoader(SysData.Param.page[0]);
					Loader.addLoad(SysData.Param.page[1]);
				}
				Loader.start();
			}
			
			
		}
		
		
		//public static function ShowPreRes
		
		/**
		 * 将资源配置转换为OB对象,存放至tempResLib
		 * @param	resList
		 * @return
		 */
		private static function addResData(resList:*):void {
			var n:int = resList.children().length();
			for (var a:int = 0; a < n; a++) {
				var config:Object = ResXMLtoOBJECT.convert(resList.children()[a]);	//转换节点为OB对象
				config.parentID = (resList.@id != undefined)?resList.@id:"root";	//获取父级ID
				
				//trace(config.reset.length)
				
				Resource.addNewResource(config);
				if (resList.children()[a].children().length()) {
					addResData(resList.children()[a]);
				}
			}
			
		}
		
		
		
		
	}
}