FLEX如何读取XML文件.
FLEX读取XML文件实例教程.
XML文件:
MXML文件:
XML文件:
<?xml version=”1.0″?>
<books>
<item>
<title>The Complete Guide to Flex 2 and ActionScript 3.0</title>
</item>
<item>
<title>Programming Flex 2 (Programming)</title>
</item>
<item>
<title>Adobe Flex 2: Training from the Source</title>
</item>
</books>
<books>
<item>
<title>The Complete Guide to Flex 2 and ActionScript 3.0</title>
</item>
<item>
<title>Programming Flex 2 (Programming)</title>
</item>
<item>
<title>Adobe Flex 2: Training from the Source</title>
</item>
</books>
MXML文件:
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”
initialize=”myService.send()”>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var myData:ArrayCollection;
private function resultHandler(event:ResultEvent):void {
myData = event.result.books.item;
}
]]>
</mx:Script>
<mx:HTTPService id=”myService”
url=”books.xml”
result=”resultHandler(event)”/>
<mx:Text id=”something” text=”{myData.getItemAt(0).title}”/>
</mx:Application>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”
initialize=”myService.send()”>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var myData:ArrayCollection;
private function resultHandler(event:ResultEvent):void {
myData = event.result.books.item;
}
]]>
</mx:Script>
<mx:HTTPService id=”myService”
url=”books.xml”
result=”resultHandler(event)”/>
<mx:Text id=”something” text=”{myData.getItemAt(0).title}”/>
</mx:Application>