2 Replies Latest reply on Feb 19, 2009 4:01 AM by alice_data

    How to detect if a CheckBox is Unchecked?

    alice_data Level 1

      I am wondering if anyone on this list has tried to detect if a checkbox has been checked, since I used ceckBox[idx].selected == false does not seem to work. What I would like to do is to delete the element when the checkbox is "unchecked".

      Attached is the code, and right now my code works if you add new elements to the Array, but if you uncheck items, it unchecks, but the value is still stored in the Array. Is there some kind of function I am missing here? I tried using removeItem, and it tells me it is not a function.

      Thanks in advance.

        • 1. Re: How to detect if a CheckBox is Unchecked?
          atta707 Level 2
          well, to keep things really simple how about reinitializing the array first thing in your listener:

          private function button_click(evt:Event):void {
          selArr = new Array();


          That should take care of it! and you can also remove the checks like:

          if (selArr.indexOf(checkBox[idx].label) == -1) {

          Hope this helps.


          • 2. How to detect if a CheckBox is Unchecked?
            alice_data Level 1

            I don't think I can use the first suggestion you made, because i am not supposed to recreate the array. What I am trying to do is to "track" the changes of the array, so that I am only adding elements to the array instead of recreating the entire thing.

            Anyway, I fiddled around with what you mentioned for point 2 and got everything fixed by inserting a separate statement checkBox[idx].selected == false to check if a check is committed, and then a splice function to delete the element from the array.

            Thanks for your help.