package
{
import fl.controls.Button;
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
import flash.events.Event;
import flash.events.MouseEvent;
public class ButtonCell extends Button implements ICellRenderer
{
private var _listData:ListData;
private var _data:Object;
public function ButtonCell()
{
super();
addEventListener(MouseEvent.CLICK, onButtonClick);
}
public function set data(d:Object):void
{
_data = d;
}
public function get data():Object
{
return _data;
}
public function get listData():ListData
{
return _listData;
}
public function set listData(value:ListData):void
{
_listData = value;
}
override public function get selected():Boolean
{
return _selected;
}
override public function set selected(value:Boolean):void
{
}
public function onButtonClick(event:MouseEvent)
{
// do something
}
}
}
In your .fla file make sure you have the imports:
import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.controls.listClasses.CellRenderer;
import ButtonCell;
Then, in your .fla file use this to create the column (where 'myDataGrid' is the name of your dataGrid instance):
var btnCol:DataGridColumn = new DataGridColumn("buttonColumnTitle");
btnCol.cellRenderer = ButtonCell;
btnCol.editable = false;
myDataGrid.addColumn(btnCol);
To set the button label, just set the text like you would any other dataGrid cell:
myDataGrid.addItem({buttonColumnTitle:"Button Label"})
No comments:
Post a Comment