Actionscript 3 多个复选框

Actionscript 3 multiple checkboxes

我有 5 个复选框和 5 个数值步进器。 当 checkbox5 选中附加到它的数字步进器时,必须启用它并且必须禁用其他 4 个步进器,即使其他 4 个复选框之一被选中也是如此。

但是当未选中复选框 5 时,必须启用附加到所选复选框的数字步进器。

我试过两种方法

import flash.events.MouseEvent;
CHECK5_CHK.addEventListener(MouseEvent.CLICK, ALL_CHECK_LSN);
CHECK1_CHK.addEventListener(MouseEvent.CLICK, ALL_CHECK_LSN);
CHECK2_CHK.addEventListener(MouseEvent.CLICK, ALL_CHECK_LSN);
CHECK3_CHK.addEventListener(MouseEvent.CLICK, ALL_CHECK_LSN);
CHECK4_CHK.addEventListener(MouseEvent.CLICK, ALL_CHECK_LSN);


function ALL_CHECK_LSN(event: MouseEvent): void {
if (CHECK5_CHK == true){
 CHECK1_NUM.enabled = false;
 CHECK2_NUM.enabled = false;
 CHECK3_NUM.enabled = false;
 CHECK4_NUM.enabled = false;
}else if ((CHECK1_CHK.selected == true)&&(CHECK5_CHK.selected == false)){
CHECK1_NUM.enabled = true;
}else if ((CHECK2_CHK.selected == true)&&(CHECK5_CHK.selected == false)){
CHECK2_NUM.enabled = true;
}else if ((CHECK3_STR_CHK.selected == true)&&(CHECK5_CHK.selected == false)){
CHECK3_STR_NUM.enabled = true;
}else if ((CHECK4_STR_CHK.selected == true)&&(CHECK5_CHK.selected == false)){
CHECK4_STR_NUM.enabled = true;
 }else {
  Check1_NUM.enabled = false;
  Check2_NUM.enabled = false;
  Check3_NUM.enabled = false;
  Check4_NUM.enabled = false;
  Check5_NUM.enabled = false;
}
}

import flash.events.MouseEvent;

CHECK5_CHK.addEventListener(MouseEvent.CLICK, CHECK5_LSN);
CHECK1_CHK.addEventListener(MouseEvent.CLICK, CHECK1_LSN);
CHECK2_CHK.addEventListener(MouseEvent.CLICK, CHECK2_LSN);
CHECK3_CHK.addEventListener(MouseEvent.CLICK, CHECK3_LSN);
CHECK4_CHK.addEventListener(MouseEvent.CLICK, CHECK4_LSN);


function CHECK1_LSN(event: MouseEvent): void {
if ((CHECK1_CHK.selected == true) && (CHECK5_CHK.selected == false)){
CHECK1_NUM.enabled = true;
} else {
CHECK1_NUM.enabled = false;
}
}

function CHECK2_LSN(event: MouseEvent): void {
if ((CHECK2_CHK.selected == true) && (CHECK5_CHK.selected == false)){
CHECK2_NUM.enabled = true;
 } else {
  CHECK2_NUM.enabled = false;
}
}

function CHECK3_LSN(event: MouseEvent): void {
if ((CHECK3_CHK.selected == true) && (CHECK5_CHK.selected == false)){
CHECK3_NUM.enabled = true;
} else {
CHECK3_NUM.enabled = false;
}
}

function CHECK4_LSN(event: MouseEvent): void {
if ((CHECK4_CHK.selected == true) && (CHECK5_CHK.selected == false)){
CHECK4_NUM.enabled = true;
} else {
CHECK4_NUM.enabled = false;
}
}

function CHECK5_LSN(event: MouseEvent): void {
if (CHECK5_CHK.selected == true) {
 CHECK1_NUM.enabled = false;
 CHECK2_NUM.enabled = false;
 CHECK3_NUM.enabled = false;
 CHECK4_NUM.enabled = false;

} else {
 CHECK1_NUM.enabled = true;
 CHECK2_NUM.enabled = true;
 CHECK3_NUM.enabled = true;
 CHECK4_NUM.enabled = true;
}
}

我做错了什么?)

如果您只想在未选中 CHECK5_CHK 时启用与所选复选框关联的步进器,否则启用 CHECK5_NUM,您可以简单地这样做:

// I think that you should disable all steppers before selecting checkboxes
CHECK1_NUM.enabled = 
    CHECK2_NUM.enabled =
        CHECK3_NUM.enabled = 
            CHECK4_NUM.enabled = 
                CHECK5_NUM.enabled = false;

function ALL_CHECK_LSN(event: MouseEvent):void {

    CHECK1_NUM.enabled = !CHECK5_CHK.selected && CHECK1_CHK.selected; 
    /* you can write it like this : 
        if(CHECK5_CHK.selected == false && CHECK1_CHK.selected == true){
            CHECK1_NUM.enabled = true;
        } else {
            CHECK1_NUM.enabled = false
        }
    */  
    CHECK2_NUM.enabled = !CHECK5_CHK.selected && CHECK2_CHK.selected;
    CHECK3_NUM.enabled = !CHECK5_CHK.selected && CHECK3_CHK.selected;
    CHECK4_NUM.enabled = !CHECK5_CHK.selected && CHECK4_CHK.selected;
    CHECK5_NUM.enabled = CHECK5_CHK.selected;

}

希望能帮到你。