flex解析xml两方式_带个发表情zip

1.使用httpService

2.使用urlLoader

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();loaderxml();" verticalScrollPolicy="off" horizontalScrollPolicy="off">
	<mx:HTTPService id="parseXml" showBusyCursor="true" url="brow.xml">
		
	</mx:HTTPService>
	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			private var arr:ArrayCollection
			private function init(){
				parseXml.send();
				parseXml.addEventListener(ResultEvent.RESULT,result);
				parseXml.addEventListener(FaultEvent.FAULT,fault);
			}
			
			private function fault(event:FaultEvent){
				trace(event.message)
			}
			private function result(event:ResultEvent){
				trace("result:"+event.result.brows.brow as ArrayCollection);//输出null;单下边
				arr=event.result.brows.brow //这可以转成ArrayCollecation
				trace(arr.getItemAt(0).sp.toString());//输出kang
				trace("label:"+arr.getItemAt(0).label.toString());//输出""
				
				trace(parseXml.lastResult.brows.brow[0].sp);//输出kang
				trace(parseXml.lastResult.brows.brow[1].icon)//输出 img/Face/1.swf
			}
			private function loaderxml(){
				var url="brow.xml";
				var ul:URLLoader=new URLLoader();
				ul.load(new URLRequest(url));
				ul.addEventListener(Event.COMPLETE,areadyLoad);	
			}
			private function areadyLoad(event:Event){
				var xml:XML=XML(event.target.data);
				trace(xml.brow[0].sp);//输出kang
				trace(xml.brow[1].@data);//输出1
				
				var obj1:Object="<sp>hello</sp>";
				var obj2:Object="<ss>sdfasf</ss>"
				xml.appendChild(obj1);
				trace(xml.toXMLString());//最后加了一句<sp>hello</sp>
			}
		]]>
	</mx:Script>
</mx:Application>

  brow.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<brows>
	            <brow data="0" tp="微笑" label="" icon="img/Face/0.swf">
	            <sp>kang</sp>
	            </brow>
				<brow data="1" tp="撇嘴" label="a" icon="img/Face/1.swf"/>
				<brow data="2" tp="撇嘴" label="b" icon="img/Face/2.swf"/>
				<brow data="3" tp="撇嘴" label="c" icon="img/Face/3.swf"/>
				<brow data="4" tp="撇嘴" label="d" icon="img/Face/4.swf"/>
				<brow data="5" tp="撇嘴" label="e" icon="img/Face/5.swf"/>
<brows>

 

你可能感兴趣的:(xml,Flex,Adobe)