我想在AS3的网格组件中添加动态复选框。 Here是链接。我想在Flash AS3.0中进行,而不是在Flex中进行。
答案 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;
}
}
}