1.<mx:XML>在<mx:Tree>中的使用,存储数据(labelField表示显示xml数据中label的值。showRoot为false表示不显示要结点)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Panel x="109" y="65" width="280" height="300" layout="absolute" title="使用XML组件">
<mx:Tree x="10" y="35" id="tree2" width="218" height="260" showRoot="false" labelField="@label">
<mx:dataProvider>
<mx:XML id="XMLData">
<menus>
<node label="Mail">
<node label="Inbox"/>
<node label="Personal Folder">
<node label="Demo"/>
<node label="Personal"/>
<node label="Saved Mail"/>
<node label="bar"/>
</node>
<node label="Calendar"/>
<node label="Sent"/>
<node label="Trash"/>
</node>
</menus>
</mx:XML>
</mx:dataProvider>
</mx:Tree>
</mx:Panel>
</mx:Application>
2.<mx:XMLList>的应用,存储数据 (labelField表示显示xml数据中id的值)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalAlign="left">
<mx:states>
<mx:State name="index1">
<mx:AddChild position="lastChild">
<mx:VBox id="myVBox1" x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}"
width="{myMenuBar.width}" height="248" backgroundColor="#ffffff"
backgroundAlpha="0.5">
</mx:VBox>
</mx:AddChild>
</mx:State>
<mx:State name="index2">
<mx:AddChild position="lastChild">
<mx:VBox id="myVBox2" x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}"
width="{myMenuBar.width}" height="248" backgroundColor="#f5e531"
backgroundAlpha="0.5">
</mx:VBox>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:MenuBar x="98" y="24" id="myMenuBar" dataProvider="{myXMLList}" labelField="@id" width="293" change="menuClickHandle(event)"></mx:MenuBar>
<mx:XMLList id="myXMLList" >
<menuitem id="Menu1">
<menuitem id="SubMenu1" type="radio" groupName="one"/>
<menuitem id="SubMenu2" type="radio" groupName="one"/>
</menuitem>
<menuitem id="Menu2">
</menuitem>
<menuitem id="Menu3">
</menuitem>
<menuitem id="Menu4">
<menuitem id="SubMenu3" type="radio" groupName="two"/>
<menuitem id="SubMenu4" type="radio" groupName="two"/>
<menuitem id="SubMenu5" type="radio" groupName="two"/>
</menuitem>
</mx:XMLList>
<mx:Script>
<![CDATA[
import mx.events.MenuEvent;
private function menuClickHandle(e:MenuEvent):void{
if(e.label=="SubMenu1")
currentState="index1";
else if(e.label=="SubMenu2")
currentState="index2";
else if(e.label=="SubMenu3")
currentState="index3";
else if(e.label=="SubMenu4")
currentState="index4";
else if(e.label=="SubMenu5")
currentState="index5";
}
]]>
</mx:Script>
</mx:Application>