获取树控件的节点打开,选择的事件
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600" >
<!-- ====== Properties of parent ======================= -->
<s:layout>
<s:BasicLayout/>
</s:layout>
<!-- ====== MetaData =================================== -->
<!-- ====== Styles ===================================== -->
<!-- ====== Script ===================================== -->
<fx:Script>
<![CDATA[
import flash.events.*;
import mx.controls.*;
import mx.events.*;
protected function tree1_itemOpenHandler(event:TreeEvent):void
{
forOpen.text = event.item.@label
}
protected function tree1_changeHandler(event:ListEvent):void
{
var theData:String = ""
if (event.currentTarget.selectedItem.@data) {
theData = " Data: " + event.currentTarget.selectedItem.@data;
}
forChange.text = event.currentTarget.selectedItem.@label + theData;
}
protected function tree1_creationCompleteHandler(event:FlexEvent):void
{
tree1.expandItem(MailBox.getItemAt(0), true);
forOpen.text=tree1.openItems[0].@label;
}
]]>
</fx:Script>
<!-- ====== Declarations =============================== -->
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<!-- ====== UI Components ============================== -->
<mx:Tree id="tree1"
labelField="@label"
showRoot="true"
width="160" x="16" y="99"
itemOpen="tree1_itemOpenHandler(event)"
change="tree1_changeHandler(event)"
creationComplete="tree1_creationCompleteHandler(event)">
<mx:XMLListCollection id="MailBox">
<fx:XMLList>
<node label="Mail" data="100">
<node label="Inbox" data="70"/>
<node label="Personal Folder" data="10">
<node label="Business" data="2"/>
<node label="Demo" data="3"/>
<node label="Personal" data="0" isBranch="true" />
<node label="Saved Mail" data="5" />
</node>
<node label="Sent" data="15"/>
<node label="Trash" data="5"/>
</node>
</fx:XMLList>
</mx:XMLListCollection>
</mx:Tree>
<mx:Form>
<mx:FormItem label="Change Event:">
<mx:Label id="forChange" width="150"/>
</mx:FormItem>
<mx:FormItem label="Open Event:">
<mx:Label id="forOpen" width="150"/>
</mx:FormItem>
</mx:Form>
</s:Application>