3 Replies Latest reply on Jul 15, 2010 4:56 AM by Ned Murphy

    Quiz problem - click the Right Answer(s) using Check Boxes

    aa5565

      Hi All,

       

      As part of  a flash 8 project, I have created a Quiz using Check Boxes.

       

      In Question 1, I have got 8 Ckeckboxes in 2 columns of which check boxes:- B, D. E, and H are correct answers.

      The rest are the wrong answers. However user may tick all the right ones and also tick couple of wrong answers (eg user may

      tick B, D, E, H and also A and F or may  infact tick all the boxes).

       

      What I want is when user selects only the correct boxes (B, D, E, H) answer equals 1 point (right answer).

      However if they select:-

       

      A, C, E, G equals 0 point (wrong).

      B, D, E, H and combination of other checkboxes equals 0 point (wrong answer).

      A, C, F, G and combination of other checkboxes equals 0 point (wrong answer).

      A, B, C, D, E, F, G, H equals 0 point (wrong answer).

       

      answer equals 0 point.

       

      I need a method using actionscript 2.0 to work  this out. I think I've worked out the first part where user selects only the correct boxes (B, D, E, H) equals 1 point, and if user only selects the wrong boxes (A, C, F, G) equals 0 point. But I can't work out other parts. I tried using logical || (OR), but does not seem to work properly.

       

      Also I would like a mehod of working out which questions user got right and wrong, and displaying a message eg message saying You got questions 1, 3, 5 right but you got questions 2, 4 wrong.

       

      I hope anyone can help with AS2.0 code/examples etc.

       

       

      Thanks very much.

        • 1. Re: Quiz problem - click the Right Answer(s) using Check Boxes
          Ned Murphy Adobe Community Professional & MVP

          Show your conditional that didn't work.  Since there appears to be only one correct answer, you should be able to use a series of && conditionals, in the sense of...

           

          if(B && D && E && H  && !A && !C && !F && !G)[

            // award 1 point

          } else {

            // award 0 points

          }

           

          As far as reporting at the end, each time you score a question, you should store the result (correct vs incorrect) in an array and go thru that array at the end to present those results.

          • 2. Re: Quiz problem - click the Right Answer(s) using Check Boxes
            aa5565 Level 1

            Hi Ned,

             

            First I like to thank you for your responce to my question.

             

            I tried your code but still causes the same problem. Sadly I can't upload the flash

            files to show you. However I have written the code below:-

             

            /******************** Question 1 ***********************/

            /****** checkBox1a ***********/

            checkBox1a.selected = false;

            ans1a = 0;

            var checkboxListener:object = new object();

            checkboxListener.click = function(evt_obj:object){

                if(evt_obj.target.selected) {

                     ans1a = 0;   // Wrong Answer

                } else {

                     ans1a = 0;

                }  

            }

             

            checkBox1a.addEventListener("click", checkboxListener);

             

            /***** checkBox1b ********/

            checkBox1b.selected = false;

            ans1b = 0;

            checkboxlistener.click = function(evt_obj:object){

                 if(evt_obj.target.selected) {

                       ans1b = 1;   // Right Answer

                 }else {

                       ans1b = 0;

                 }

            }

             

            checkb1b.addEventListener("click", checkboxListener);

             

            /****  The other checkboxes are similar to the above *******/

             

            Hence mentioned in my last message

             

            ans1b, ans1d, ans1e and ans1h are the correct(right) answers.  ans1a, ans1c, ans1f and ans1g are the wrong answers.

             

            So when user presses checkresult Button It calculates the following:

             

            checkResultButt.onRelease = function() {

             

                    /* my origional code */

                    if ((ans1b ==1) && (ans1d == 1) &&(ans1e ==1) && (ans1h ==1) {

                            ans1 = 1;

                   } else {

                             ans1 = 0;

                  }

                

                  /* Your code */

                  if(ans1b && ans1d && ans1e && ans1h && !ans1a && !ans1c && !ans1f && !ans1g) {

                    ans1 = 1;

                  } else {

                    ans1 = 0;

                   }

                  result = ans1;

               

            }

             

            I hope this code helps you understand what the problem is.

            Is it possible for me to email my flash file so you can look at it and test it?

            if you require further information please let me know

             

            Once again thanks for help.

            • 3. Re: Quiz problem - click the Right Answer(s) using Check Boxes
              Ned Murphy Adobe Community Professional & MVP

              Try tracing all of the ans# values before you test them to see if they are what you expect them to be.   I have a feeling they aren't... your listener implementation is questionable (which function does the click work with and ans1a is 0 in both cases (shouldn't be)).  I would just test the selected properties of the objects rather than trying to assign that status to something else in another variable form...

               

              if(checkBox1b.selected  && etc...) {