在数组中选中as3复选框

时间:2013-02-18 11:28:49

标签: arrays actionscript-3 checkbox selected

我在数组中有20个复选框,而不是标记所有复选框。并且有3个动态文本。全部复选框启用为true。我想,如果选中任何复选框,则首先选中文本字段复选框名称。第二和第三选择同样第二和第三文本文件写。 17结束复选框以获得启用的错误

   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="";}
}

1 个答案:

答案 0 :(得分: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;
                }
            }
        }
    }
}