flex loadxml

阅读更多
package
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.system.Capabilities;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	import spark.components.Application;
	
	public class LoadXML
	{
		public static const loadXMLCompleteEvent:String = "load_xml_complete";
		public static const loadXMLFaultEvent:String = "load_xml_fault";
		
		public static var remoteStr:String = "";
        
        public static var moduleList:XMLList;
        
        private static var http:HTTPService = null;
        
		public function LoadXML()
		{
		}
		
		public static function loadXml(url:String="configData.xml"):void
		{
			http = new HTTPService();
			http.url = url;
			http.resultFormat = "e4x";
			http.addEventListener(ResultEvent.RESULT,xmlresult);
			http.addEventListener(FaultEvent.FAULT,xmlfault);
			http.send();
			
			function xmlresult(event:ResultEvent):void
			{
				var configXML:XML = event.result as XML;
				if(configXML)
				{
					// 网站根目录ip地址
					var server:String = (configXML.child("server") as XMLList)[0].toString();
					Constants.SERVER = server;
					
					Constants.ALERTTIME = Number(configXML.alertTime[0].toString() || "1000");
					
				}
				EventBus.getInstance().dispatchEvent(new Event("load_xml_complete"));
			}
			
			function xmlfault(e:FaultEvent):void
			{
				EventBus.getInstance().dispatchEvent(new Event("load_xml_fault"));
			}
		}
        
	}
}




    
    http://192.168.0.151:8089/app/
    
    2000

你可能感兴趣的:(flex loadxml)