8 Replies Latest reply on Jul 22, 2010 4:46 PM by Ned Murphy

    unselecting checkbox not making answer disappear

    webster_1c

      Hi all

       

      I almost have this bit of code working how i want it too, but just have one query. i would just like to set it up so that if a user unchecks the checkbox the answer disappears, at the momment the answer does disappear if you check another checkbox, which is fine, but if a user unselects a checkbox, so there are no checkboxes selected then there should be no answer being shown.

       

      Hope this makes sense and that someone can help

       

      Thanks

       

      See code below

       

       

      /*****/

      checkBox1a.selected = false;
      ans1 = 0;
      var checkboxListener:Object = new Object();
      checkboxListener.click = function(evt_obj:Object) {
      if (evt_obj.target.selected) {
        //evt_obj.target.label = "Selected!";
        checkBox1b.selected = false;
        checkBox1c.selected = false;
        checkbox1d.selected = false;
        ans1 = 0;
        trace(ans1);
        txtOutput.text="No it's the wrong Answer!";
      } else {
        //evt_obj.target.label = "Unselected!";
        ans1 = 0;
        trace(ans1);
      }
      };
      checkBox1a.addEventListener("click", checkboxListener);
      /*****/

       


      checkBox1b.selected = false;
      ans1 = 0;
      var checkboxListener:Object = new Object();
      checkboxListener.click = function(evt_obj:Object) {
      if (evt_obj.target.selected) {
        checkBox1a.selected = false;
        checkBox1c.selected = false;
        checkbox1d.selected = false;
       
        //evt_obj.target.label = "Selected!";
        ans1 = 1;
        trace(ans1);
        txtOutput.text="Brilliant You got the Right Answer!";
      } else {
        //evt_obj.target.label = "Unselected!";
        ans1 = 0;
        trace(ans1);
      }
      };
      checkBox1b.addEventListener("click", checkboxListener);
      /***/

        • 1. Re: unselecting checkbox not making answer disappear
          Ned Murphy Adobe Community Professional & MVP

          You need to explain what you are calling the answer.

          • 2. Re: unselecting checkbox not making answer disappear
            Ned Murphy Adobe Community Professional & MVP

            You are creating/duplicating code that won't work for you.  You can only have one listener by that variable name, and you can combine the listener functions into one... the following would replace all of your code.

             

            checkBox1a.selected = false;
            ans1 = 0;
            var checkboxListener:Object = new Object();
            checkboxListener.click = function(evt_obj:Object) {

            if (evt_obj.target.selected) {
              checkBox1a.selected = false;
              checkBox1b.selected = false;
              checkBox1c.selected = false;
              checkBox1d.selected = false;
             
              evt_obj.target.selected = true;
             
              if(evt_obj.target != checkBox1b){
                 txtOutput.text="No it's the wrong Answer!";
                 ans1 = 0;
              } else {
                 txtOutput.text="Brilliant You got the Right Answer!";  
                 ans1 = 1;
              }
            } else {
              ans1 = 0;

            // here is where you will do whatever you are calling "making answer disappear"
            }
            };
            checkBox1a.addEventListener("click", checkboxListener);
            checkBox1b.addEventListener("click", checkboxListener);
            checkBox1c.addEventListener("click", checkboxListener);
            checkBox1d.addEventListener("click", checkboxListener);

            • 3. Re: unselecting checkbox not making answer disappear
              webster_1c Level 1

              Hi Ned

               

              Many thanks for your reply, im very much new at this and trying to cobble stuff together and learn at the same time. I copied and pasted your code and it does not seem to work, not sure if you wanted me to add to what you have kindly produced. After i run the code, and i unselect a box after i have selected it the answer remains visible.

               

              Also the reason i duplicated the code was becuase i needed indvidual feedback for each response, perhaps i could do this with if/else statements.

               

              Thanks

              • 4. Re: unselecting checkbox not making answer disappear
                Ned Murphy Adobe Community Professional & MVP

                You've left the mystery remaining.  I do not know what you are considering to be the answer, so I cannot tell you how to make it disappear.  But I have marked in my code where you would make it happen.

                • 5. Re: unselecting checkbox not making answer disappear
                  webster_1c Level 1

                  Hi Ned

                   

                  Sorry, allow me to clarify, there is no answer as such,  each of the options once chosen should present the user with feedback and once they unselect an option that feedback should become invisible or hide. The feedback will usually be a paragraph of text building on the option they have selected. Does that make sense ?

                  • 6. Re: unselecting checkbox not making answer disappear
                    Ned Murphy Adobe Community Professional & MVP

                    Not meaning to offend, but it makes perfectly clear sense when you describe it in terms of what you have in the file/code.  I am going to assume it involves the txtOutput textfield that has status written into it when a checkbox is selected... the red code is what will remove that text...

                     

                    checkBox1a.selected = false;
                    ans1 = 0;
                    var checkboxListener:Object = new Object();
                    checkboxListener.click = function(evt_obj:Object) {

                    if (evt_obj.target.selected) {
                      checkBox1a.selected = false;
                      checkBox1b.selected = false;
                      checkBox1c.selected = false;
                      checkBox1d.selected = false;
                     
                      evt_obj.target.selected = true;
                     
                      if(evt_obj.target != checkBox1b){
                         txtOutput.text="No it's the wrong Answer!";
                         ans1 = 0;
                      } else {
                         txtOutput.text="Brilliant You got the Right Answer!";  
                         ans1 = 1;
                      }
                    } else {
                      ans1 = 0;

                      txtOutput.text = "";
                    }
                    };
                    checkBox1a.addEventListener("click", checkboxListener);
                    checkBox1b.addEventListener("click", checkboxListener);
                    checkBox1c.addEventListener("click", checkboxListener);
                    checkBox1d.addEventListener("click", checkboxListener);

                    • 7. Re: unselecting checkbox not making answer disappear
                      webster_1c Level 1

                      Hi Ned

                       

                      No offence taken, thank you, you have solved my issue despite my ramblings. much appreciated.

                       

                      Cheers