<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="absolute" xmlns:ns1="com.component.*">
<mx:Script>
<![CDATA[
import com.component.DataHBox;
import com.component.GridDataObject;
import mx.collections.ArrayCollection;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.Alert;
[Bindable]
var xml:XML=
<root><data name='德阳市卫生执法监督所' pid='10777 ' czjb='2' flag="2"/>
<data name='泰山社区卫生服务中心' pid='10795 ' czjb='3' flag="3"/>
<data name='八角镇卫生院' pid='10783 ' czjb='2' flag="2"/>
<data name='德阳市第二人民医院' pid='10770 ' czjb='3' flag="3"/>
<data name='扬嘉镇卫生院' pid='10794 ' czjb='2' flag="2"/>
</root>;
[Bindable]
var arry:ArrayCollection=new ArrayCollection;
function test(evt:Event):void{
var s:DataHBox=DataHBox(evt.currentTarget);
Alert.show(grid.selectedItem.@name+":"+":"+grid.selectedItem.@index+":"+s.itemValue)
}
function init():void{
var length:int=xml.data.length();
var a:Array=[];
for(var i:int=0;i<length;i++){
var s:GridDataObject=new GridDataObject;
s.name=xml.data[i].@name;
s.pid=xml.data[i].@pid;
s.czjb=xml.data[i].@czjb;
s.flag=xml.data[i].@czjb;
s.index=i;
arry.addItem(s);
}
}
]]>
</mx:Script>
<mx:DataGrid id="grid" x="317.5" y="137" dataProvider="{xml.data}" width="314" height="181">
<mx:columns>
<mx:DataGridColumn headerText="name" dataField="name"/>
<mx:DataGridColumn headerText="czjb" dataField="czjb" >
<mx:itemRenderer>
<mx:Component>
<ns1:DataHBox data="{data}" width="100%" height="100%" />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>
------------------------------------------------------------------------------------------
DataHBox.as
用途:datagrid控件的 内联组件(itemRenderer)显示多个单选按钮
package com.component
{
import flash.events.Event;
import mx.containers.HBox;
import mx.controls.RadioButton;
import mx.controls.RadioButtonGroup;
public class DataHBox extends HBox
{
public function DataHBox()
{
super();
group=new RadioButtonGroup;
radio1=new RadioButton;radio2=new RadioButton; radio3=new RadioButton;
radio1.name="1";radio2.name="2";radio3.name="3";
radio1.group=group;radio2.group=group; radio3.group=group;
this.addChild(radio1);this.addChild(radio2);this.addChild(radio3);
this.horizontalScrollPolicy="off";this.verticalScrollPolicy="off";
radio1.addEventListener('click',onClick);
radio2.addEventListener('click',onClick);
radio3.addEventListener('click',onClick);
}
public static var index:int=0;
public var group:RadioButtonGroup;
public var radio1:RadioButton;
public var radio2:RadioButton;
public var radio3:RadioButton;
public var itemValue:String="";
override public function set data(value:Object):void{
super.data=value;
radio1.selected=false;
radio1.label="查看";radio2.label="编辑"; radio3.label="查看和编辑";
radio2.selected=false; radio3.selected=false;
index++;
if(data!=null&&data.@flag=='1'){
radio1.selected=true;
}else if(data!=null&&data.@flag=='2'){
radio2.selected=true;
}else if(data!=null&&data.@flag=='3'){
radio3.selected=true;
}
}
function onClick(event:Event):void{
var radio:RadioButton= RadioButton(event.currentTarget);
if(radio.name=="1"){
data.@flag="1";
itemValue="1";
}
if(radio.name=="2"){
data.@flag="2";
itemValue="2";
}
if(radio.name=="3"){
data.@flag="3";
itemValue="3";
}
}
}
}
---------------------------------------------------结束------------------------------------------------------------------------------
; [Bindable] var arry:ArrayCollection=new ArrayCollection; function test(evt:Event):void{ var s:DataHBox=DataHBox(evt.currentTarget); Alert.show(grid.selectedItem.@name+":"+":"+grid.selectedItem.@index+":"+s.itemValue) } function init():void{ var length:int=xml.data.length(); var a:Array=[]; for(var i:int=0;i