The following is my solution:
1- Create a custom TreeItemRenderer as follows:
RadioButtonTreeItemRendere
r.as
__________________________
__________
__________
_____
package
{
import flash.events.Event;
import mx.controls.RadioButton;
import mx.controls.RadioButtonGro
up;
import mx.controls.treeClasses.*;
public class RadioButtonTreeItemRendere
r extends TreeItemRenderer
{
public var RadioBtn:RadioButton;
public var RadioBtnGR:RadioButtonGrou
p
public var itemXml:XML;
public function RadioButtonTreeItemRendere
r()
{
super();
mouseEnabled = false;
}
override public function set data(value:Object):void{
if(value != null){
super.data = value;
this.itemXml = XML(value);
if(this.itemXml.@checked == true ){
this.RadioBtn.selected = true;
}else{
this.RadioBtn.selected = false;
}
}
}
override protected function createChildren():void{
super.createChildren();
RadioBtn = new RadioButton();
RadioBtnGR = new RadioButtonGroup();
RadioBtn.group = RadioBtnGR;
addChild(RadioBtn);
}
override protected function updateDisplayList(unscaled
Width:Numb
er, unscaledHeight:Number):voi
d{
super.updateDisplayList(un
scaledWidt
h,unscaled
Height);
if(super.data){
var tld:TreeListData = TreeListData(super.listDat
a);
if(tld.hasChildren){
this.RadioBtn.visible = false;
}else{
this.RadioBtn.visible = true;
}
if(RadioBtn.visible){
this.RadioBtn.x = super.label.x
super.label.x = this.RadioBtn.x + 17;
this.RadioBtn.y = super.label.y+8;
}
}
}
}
}
__________________________
__________
______
2- application code is :
<?xml version="1.0"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF">
<mx:XML format="e4x" id="myData">
<root>
<item id="item1" label="List A">
<part id="part1" label="part1" checked = "true" parentid="item1"/>
<part id="part2" label="part2" checked = "false" parentid="item1"/>
</item>
<item id="item2" label="List B">
<part id="part1" label="part1" checked = "false" parentid="item2"/>
<part id="part2" label="part2" checked = "false" parentid="item2"/>
<part id="part3" label="part3" checked = "true" parentid="item2"/>
<part id="part4" label="part4" checked = "false" parentid="item2"/>
<part id="part5" label="part5" checked = "false" parentid="item2"/>
</item>
<item id="item3" label="Item c">
<part id="part1" label="part1" checked = "false" parentid="item3"/>
<part id="part2" label="part2" checked = "true" parentid="item3"/>
</item>
</root>
</mx:XML>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollec
tion;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private function TreeClickHandler(event:Eve
nt):void
{
var selectedXmlList:XMLList;
var itemObject:Object = event.currentTarget.select
edItem;
if (!myTree.dataDescriptor.is
Branch(ite
mObject)) {
selectedXmlList = myData.item.part.(@parenti
d == itemObject.@parentid);
processSelection(selectedX
mlList,ite
mObject.@i
d);
}
}
private function processSelection(list:XMLL
ist,Objid:
String):vo
id {
var item:XML;
for each(item in list) {
if (item.@id!=Objid)
{
item.@checked = false;
}else
{
item.@checked = true;
}
}
}
]]>
</mx:Script>
<mx:Panel width="75%" height="75%">
<mx:Tree
id="myTree"
itemClick="TreeClickHandle
r(event)"
itemRenderer="RadioButtonT
reeItemRen
derer"
showRoot="false"
width="100%"
height="100%"
labelField="@label"
folderClosedIcon="{null}"
folderOpenIcon="{null}"
defaultLeafIcon="{null}"
dataProvider="{myData}"
openItems="{myData..item}"
>
</mx:Tree>
</mx:Panel>
</mx:Application>