我正在尝试在 Flash 中的 dataGrid 中创建按钮。但是,我是一个初学者,我现在不知道如何使生成按钮列的函数获取我需要用于每个按钮的参数。我需要每个按钮都有一个特定的标签,如果我单击该按钮,它将 googleURL 复制到剪贴板。
我不知道如何将变量“buttonLabel”和“googleURL”传递给该函数......
这是代码的 .fla 部分:
googleURL = "www.someadress.com";
buttonLabel = "someLabel";
var btnCol:DataGridColumn = new DataGridColumn("buttonColumnTitle");
btnCol.cellRenderer = ButtonCell;
btnCol.editable = false;
tabulka.addColumn(btnCol);
这是 ButtonCell 类:
package
{
import flash.desktop.Clipboard;
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 var _buttonLabel:String;
public var _googleURL:String;
public function ButtonCell()
{
super();
//_buttonLabel = buttonLabel;
//_googleURL = googleURL;
this.label = _buttonLabel;
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)
{
System.setClipboard(_googleURL);
}
}
}
#######################################
哇,这项工作完美无缺,这就是问题所在。太感谢了!!但是,还有一件事我不确定……当我想添加更多按钮时,它只显示最后一个按钮……我不确定出了什么问题。这是绘制 5 个项目但按钮的示例 sript - 只有最后一个......
import ButtonCell;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.controls.listClasses.CellRenderer;
import fl.controls.DataGrid;
import fl.data.DataProvider;
var googleURL:String = "www";
var buttonLabel:String = "bt";
var provide = new DataProvider;
var tabulka:DataGrid = new DataGrid();
tabulka.x = 50;
tabulka.y = 50;
addChild(tabulka);
tabulka.setSize(400, 300);
tabulka.columns = ["Parcela","Odkaz"];
tabulka.columns[0].width = 50;
tabulka.columns[1].width = 350;
tabulka.selectable = false;
tabulka.dataProvider = provide;
var btnCol:DataGridColumn = new DataGridColumn("Copy");
tabulka.addColumn(btnCol);
for (var i = 0; i<5; i++){
provide.addItem({Parcela:"Item "+i});
btnCol.cellRenderer = new ButtonCell(buttonLabel = "bt"+i, googleURL = "www" + i);
}