0

我在数组中有 20 个复选框,而不是标记所有复选框。并且有3个动态文本。所有复选框启用为真。我希望,如果选择了任何复选框,则第一个文本字段选择的复选框名称写入。第二个和第三个选择同样的第二个和第三个文本文件写入。end of 17 复选框以启用 false

   import fl.controls.CheckBox;
   var arr:Array = [cb1,cb2,cb3,cb4,cb5,cb6,cb7,cb8,cb9,cb10,......]; //20 Checkbox

   // how do I find i = selected checkbox in array    

   i.addEventListener(MouseEvent.CLICK,myselect);
   function myselect(e:MouseEvent):void{
    trace(i.name);
       if (i.selected==true){
       yaz.text="Select"+" "+i.name;
}else {yaz.text="";}
}
4

1 回答 1

0

我认为您需要(文档类):

package  {

    import fl.controls.CheckBox;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import fl.controls.Label;

    public class Test extends Sprite {

        public var cbBox:Sprite;
        public var tfBox:Sprite;

        public function Test() {
            init();
        }

        public function init()
        {
            cbBox = new Sprite();
            cbBox.x = 10;
            addChild(cbBox);

            tfBox = new Sprite();
            tfBox.x = 200;
            addChild(tfBox);

            for (var i:uint=0; i<20; i++)
            {
                var cb:CheckBox = new CheckBox();
                cb.addEventListener(MouseEvent.CLICK, onClickHandler);
                cb.label = (i + 1).toString();
                cb.y = i* 20;
                cbBox.addChild(cb);
            }
        }

        public function onClickHandler(event:MouseEvent):void
        {
            if (tfBox.numChildren < 3)
            {
                var label:Label = new Label();
                label.width = 200;
                label.height = 20;
                label.y = tfBox.numChildren * 20;
                label.text = CheckBox(event.target).label;
                tfBox.addChild(label);
            }

            if (tfBox.numChildren == 3)
            {
                for (var i:uint = 0; i< cbBox.numChildren; i++)
                {
                    var ch:CheckBox = cbBox.getChildAt(i) as CheckBox;
                    if (!ch.selected) ch.enabled = false;
                }
            }
        }
    }
}
于 2013-02-18T15:20:57.363 回答