如何在Flash列表控件中设置复选框?
到目前为止我编码的内容:
CustomCellRenderer.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;
}
}
}
Flash IDE动作面板内部:
import fl.controls.List;
var myList:List
myList.allowMultipleSelection =true;
myList.setStyle("cellRenderer", CustomCellRenderer);
myList.addItem({label:"Burger", price:"$5.95"});
myList.addItem({label:"Fries", price:"$1.95"});
myList.addItem({label:"Burger", price:"$5.95"});
myList.addItem({label:"Fries", price:"$1.95"});
问题是显示的复选框,无法同时检查(除非单击Ctrl按钮)。
诉P>
答案 0 :(得分:1)
得到解决方案:
使用ctrlKey属性完成工作。
感谢教程:http://active.tutsplus.com/tutorials/actionscript/as3-quick-tip-hacking-the-event-flow/
ActionsPanel:
import flash.events.Event;
var myList:List
//myList.setStyle("cellRenderer", MyCellRenderer);
myList.addEventListener(MouseEvent.CLICK, hackMouseListener, true);
myList.allowMultipleSelection =true;
myList.setStyle("cellRenderer", CustomCellRenderer);
myList.addItem({label:"Burger", price:"$5.95"});
myList.addItem({label:"Fries", price:"$1.95"});
myList.addItem({label:"Burger", price:"$5.95"});
myList.addItem({label:"Fries", price:"$1.95"});
function hackMouseListener(e:MouseEvent):void{
e.ctrlKey = true;
}
CustomCellRenderer.as
package
{
import fl.controls.CheckBox;
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
import fl.controls.List ;
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;
}
public override function set selected(val_bool:Boolean):void
{
_selected = val_bool
super.selected = _selected ;
}
public override function get selected():Boolean
{
return _selected ;
}
}
}