As3在Grid组件中添加Checkbox

时间:2014-08-02 08:05:17

标签: actionscript-3 flash

我想在AS3的网格组件中添加动态复选框。 Here是链接。我想在Flash AS3.0中进行,而不是在Flex中进行。

1 个答案:

答案 0 :(得分:0)

对于自定义单元格,您需要在列上使用自定义cellRenderer。

主要

var sampleItem1:Object = {Name:"John Alpha", Number:"555-123-0101", Email:"jalpha@fictitious.com"}; 
var dg:DataGrid = new DataGrid(); 
var dgc:DataGridColumn = new DataGridColumn("Name");
dg.addColumn(dgc);
dgc = new DataGridColumn("Number");
dgc.cellRenderer = "CustomCellRenderer"; // here you set your custom renderer for this column
dg.addColumn(dgc);
dgc = new DataGridColumn("Email");
dg.addColumn(dgc); 
dg.addItem(sampleItem1);

CheckBoxCellRenderer.as

package 
{ 
    import fl.controls.CheckBox; 
    import fl.controls.listClasses.ICellRenderer; 
    import fl.controls.listClasses.ListData; 

    public class CustomCellRenderer extends CheckBox implements ICellRenderer { 
        private var _listData:ListData; 
        private var _data:Object; 
        public function CustomCellRenderer() { 
        } 

        public function set data(d:Object):void { 
            _data = d; 
            label = d.label; 
        } 

        public function get data():Object { 
            return _data; 
        } 

        public function set listData(ld:ListData):void { 
            _listData = ld; 
        } 

        public function get listData():ListData { 
            return _listData; 
        } 
    } 
}

source1 source2