3 Replies Latest reply on Feb 26, 2009 12:39 PM by kglad

    Check multiple checkboxes for selected

    chieffan Level 1
      I want to see if I can reduce my code more. I have five check boxes on the screen and when they are all checked, I want to call a function. I don't want to have a long if statement because I will re-use this and would prefer to have as streamlined as possible. Here is my code now. Thanks.

      var checkboxListener:Object = new Object();
      checkboxListener.click = function(evt_obj:Object) {
      for (cb=1; cb<6; cb++) {
      if (_root["c"+cb+"_ch"].selected) {
      nextItem()
      }
      }

      };
      for (cb=1; cb<7; cb++) {
      this["c"+cb+"_ch"].addEventListener("click",checkboxListener);
      }
      function nextItem() {
      if (c1_ch.selected && c2_ch.selected && c3_ch.selected && c4_ch.selected && c5_ch.selected && c6_ch.selected) {
      trace("do something") }
      }