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"));
			}
		}
        
	}
}


<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <!-- 服务器地址  -->
    <server>http://192.168.0.151:8089/app/</server>
    <!-- 操作成功提示框停留时间  -->
    <alertTime>2000</alertTime>
</configuration>

猜你喜欢

转载自jie66989.iteye.com/blog/1743486