0

如何在 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 按钮)。

五。

4

1 回答 1

1

得到了解决方案:

使用 ctrlKey 属性可以完成这项工作。

感谢教程:http ://active.tutsplus.com/tutorials/actionscript/as3-quick-tip-hacking-the-event-flow/

动作面板:

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 ; 


        }





    } 
}
于 2012-11-13T15:36:35.993 回答