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.RadioButtonGroup;
import mx.controls.treeClasses.*;
public class RadioButtonTreeItemRenderer extends TreeItemRenderer
{
public var RadioBtn:RadioButton;
public var RadioBtnGR:RadioButtonGroup
public var itemXml:XML;
public function RadioButtonTreeItemRenderer()
{
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(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(super.data){
var tld:TreeListData = TreeListData(super.listData);
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.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private function TreeClickHandler(event:Event):void
{
var selectedXmlList:XMLList;
var itemObject:Object = event.currentTarget.selectedItem;
if (!myTree.dataDescriptor.isBranch(itemObject)) {
selectedXmlList = myData.item.part.(@parentid == itemObject.@parentid);
processSelection(selectedXmlList,itemObject.@id);
}
}
private function processSelection(list:XMLList,Objid:String):void {
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="TreeClickHandler(event)"
itemRenderer="RadioButtonTreeItemRenderer"
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>