10 Replies Latest reply on Aug 10, 2010 8:25 AM by atrzebunia

    Radio buttons not working when I return to their frame

    atrzebunia Level 1

      I'm working on a multiple-choice quiz.  Each question is in its own frame, Q1, Q2, Q3, etc.  In Q1 frame, when I click a radio button (A, B, C, or D) it displays a Continue button which when clicked takes me to frame Q2.  In frame Q2 I have a Return button that brings me back to frame Q1.  The problem I'm having is that when I click the Return button in frame Q2, it takes me back to frame Q1 and I can click on radio buttons A, B, C, or D, but they do not display the Continue button.  In other words the radio buttons change state but they do not fire any of the actions.  Here's my code.

       

      //Q1 frame code (AS2)

      rbtnAListener = new Object();
      rbtnAListener.click = function(evt)
      {
          mc_EmptyContinue.attachMovie("btnContinue", "btn_Continue", 1);
         
          mc_EmptyContinue.btn_Continue.onRelease = function():Void
          {       
              gotoAndStop("Q2");
          }
      }
      rbtn_A.addEventListener("click", rbtnAListener);

       

       

      //Q2 frame code (AS2)

      btn_Return.onRelease = function():Void
      {
          gotoAndStop("Q1");
      }

        • 1. Re: Radio buttons not working when I return to their frame
          kglad Adobe Community Professional & MVP

          you're creating new listeners each time you enter that frame.  use:

           

          if(!rbtnAListener){

          rbtnAListener = new Object();
          rbtnAListener.click = function(evt)
          {
              mc_EmptyContinue.attachMovie("btnContinue", "btn_Continue", 1);
             
              mc_EmptyContinue.btn_Continue.onRelease = function():Void
              {       
                  gotoAndStop("Q2");
              }
          }
          rbtn_A.addEventListener("click", rbtnAListener);

           

           

          //Q2 frame code (AS2)

          btn_Return.onRelease = function():Void
          {
              gotoAndStop("Q1");
          }

          }

          • 2. Re: Radio buttons not working when I return to their frame
            atrzebunia Level 1

            kglad, this code is still not working.  I see that you've added one extra line, if(!rbtnAListener), and there is an end bracket missing.  I added the end bracket after rbtn_A.addEventListener("click", rbtnAListener).  I still don't get the rbuttons to work after returning to frame Q1.

            • 3. Re: Radio buttons not working when I return to their frame
              kglad Adobe Community Professional & MVP

              i'm not sure why you don't see the end bracket.  i put one at the end of your code.

               

              if that doesn't solve the problem you may be removing your radio button(s) at some point, in essence "orphaning" your code.   is that causing the problem?  use a

               

              trace(one of your radio buttons)

               

              outside the if-statement to confirm.

              • 4. Re: Radio buttons not working when I return to their frame
                atrzebunia Level 1

                Ah, you have the end bracket at the end of the code that is in frame Q2.  It's in the wrong place.  I need an end bracket at the end of the code in Q1.  See highlighted brackets in red below where you've placed them.  I've closed the bracket in the code in frame Q1, highlighted in green below and removed the extra bracket in the code in frame Q2.  Still no go.  I have no other code anywhere that would disable the radio buttons in frame Q1.

                 

                //Code in frame Q1

                if(!rbtnAListener)
                {
                    rbtnAListener = new Object();
                    rbtnAListener.click = function(evt)
                    {
                        mc_EmptyContinue.attachMovie("btnContinue", "btn_Continue", 1);
                       
                        mc_EmptyContinue.btn_Continue.onRelease = function():Void
                        {      
                            gotoAndStop("Q2");
                        }
                    }
                    rbtn_A.addEventListener("click", rbtnAListener);

                } // I added this bracket

                 

                //Code in frame Q2

                btn_Return.onRelease = function():Void
                {
                    gotoAndStop("Q1");
                }

                } //I deleted this bracket

                • 5. Re: Radio buttons not working when I return to their frame
                  kglad Adobe Community Professional & MVP

                  what do the trace() functions show before returning to Q1 (and clicking your rb) and after returning to Q1 (and clicking your rb).

                   


                   

                  trace(rbtn_A)
                  if(!rbtnAListener){

                  rbtnAListener = new Object();
                  rbtnAListener.click = function(evt)
                  {

                  trace("CLICK");

                      mc_EmptyContinue.attachMovie("btnContinue", "btn_Continue", 1);
                     
                      mc_EmptyContinue.btn_Continue.onRelease = function():Void
                      {       
                          gotoAndStop("Q2");
                      }
                  }
                  rbtn_A.addEventListener("click", rbtnAListener);

                   

                   

                  }
                  • 6. Re: Radio buttons not working when I return to their frame
                    atrzebunia Level 1
                    See y comments in red.  Thanks for trying to help me with this, kglad.  I know it's something simple, but I can't seem to catch it.
                    trace(rbtn_A) // output: _level0.mc_Study.rbtn_A
                    if(!rbtnAListener){

                    rbtnAListener = new Object();
                    rbtnAListener.click = function(evt)
                    {

                    trace("CLICK"); // output: CLICK (but only the first time; when I return to this frame and click again, the trace doesn't fire

                        mc_EmptyContinue.attachMovie("btnContinue", "btn_Continue", 1);
                       
                        mc_EmptyContinue.btn_Continue.onRelease = function():Void
                        {       
                            gotoAndStop("Q2");
                        }
                    }
                    rbtn_A.addEventListener("click", rbtnAListener);

                     

                     

                    }
                    • 7. Re: Radio buttons not working when I return to their frame
                      kglad Adobe Community Professional & MVP

                      try:

                       

                       

                       

                      delete mc_EmptyContinue.btn_Continue.onRelease

                      if(!rbtnAListener){

                      rbtnAListener = new Object();
                      rbtnAListener.click = function(evt)
                      {

                          mc_EmptyContinue.attachMovie("btnContinue", "btn_Continue", 1);
                         
                          mc_EmptyContinue.btn_Continue.onRelease = function():Void
                          {       
                              gotoAndStop("Q2");
                          }
                      }

                      }

                      rbtn_A.addEventListener("click", rbtnAListener);

                       

                       

                      • 8. Re: Radio buttons not working when I return to their frame
                        atrzebunia Level 1

                        Still nothing kglad.  I still can't get the trace to fire on click on rbtn_A after returning to it's frame from frame Q2.  Any other suggestions?

                        • 9. Re: Radio buttons not working when I return to their frame
                          kglad Adobe Community Professional & MVP

                          i can't think of any way solve this without downloading your fla.  maybe someone else will step-in and help because i don't download and correct files unless i'm hired.

                          • 10. Re: Radio buttons not working when I return to their frame
                            atrzebunia Level 1

                            kglad, I think you can still help me w/o sending you the FLA file.  In frame Q1 I have 3 radio buttons (radioGroupQ1).  In frame Q2 where I have the Return button that brings me back to frame Q1, I also have 3 radio buttons (radioGroupQ2).  This is the issue.  When I remove the 3 radio buttons from Q2 (radioGroupQ2) publish the SWF and click the Return button in Q2 to return to Q1, the radio buttons (radioGroupQ1) work like a charm.  And, I can go back an forth between Q1 and Q2 as such and the radio buttons always work, but the moment I add a radio button to frame Q2 and run the SWF, the radio buttons in frame Q1 stop working upon returning to frame Q1.  Can you shed some light on this?  I have unique radio button group names, so what gives?

                             

                            Ahh, just figured it out as I'm typing this.  Every radio button instance name has to have a unique name regardless of which frame it's in or what radio button group it belongs to.

                             

                            No response necessary.

                             

                            Thanks.