package net.fdms 
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.LoaderMax;
	import com.greensock.loading.XMLLoader;
	import net.fdms.Database.SysData;
	import net.fdms.Database.AnalysisData;
	import net.fdms.Resource.*;
	
	/**
	 * 2011/5/26 12:21
	 * @author Dawnboy
	 */
	public class fdms 
	{
		
		public function fdms() 
		{
			
		}
		
		public static function init(SysParam:Object):void {
			SysData.Param = SysParam;
			loadSets();
			
		}
		
		public static function loadSets():void {
			if (SysData.Param.ResSets != undefined && SysData.Param.DataSets != undefined) {
				var foo:LoaderMax = new LoaderMax({onComplete:SetsHandler,onIOError:xmlLoadErr,onProgress:ProgressBar.ProgressFunc});
				foo.append(new XMLLoader(SysData.Param.ResSets,{name:"ResSets"}));
				foo.append(new XMLLoader(SysData.Param.DataSets, { name:"DataSets"} ));
				foo.load();
			}else {
				trace("为空");
			}
		}
		
		/**
		 * 载入完成
		 * @param	e
		 */
		private static function SetsHandler(e:LoaderEvent):void {
			ProgressBar.onFinish();
			//数据导入到全局数据库
			SysData.DataSets = e.target.getLoader("DataSets").content;
			SysData.ResSets = e.target.getLoader("ResSets").content;
			
			//解析数据
			if(SysData.DataSets && SysData.ResSets){
				AnalysisData.init(SysData.DataSets);
				AnalysisRes.init();
			}else {
				xmlLoadErr();
			}
			
			//清除载入,释放内存
			e.target.getLoader("DataSets").unload();
			e.target.getLoader("ResSets").unload();
			e.target.unload();
		}
		
		
		private static function xmlLoadErr(...arg):void {
			trace("载入出错");
		}
	}

}