13 Replies Latest reply on Mar 22, 2010 4:21 PM by kglad

    Radio buttons not working after resetting

    atrzebunia

      I have a form with two radio buttons for each question.  Each question is in its own frame "Q1," "Q2," etc.  I also have a btn_Reset created to reset the form, i.e. reset all radio buttons and return to "Q1" frame.  All buttons work as they should, including resetting the radio buttons, however, once I reset the radio buttons and return to "Q1" to start over, the actions associated with each radio button upon clicking on them do not work.  Here's my code:

       

      //Frame "Begin"

      gotoAndStop("Q1")  //I also define my variables in frame "Begin"

       

      //Frame "Q1"

      rbtn_YESQ1.onPress = function():Void

      {

           attachMovie("btnReset", "btn_Reset", 1, {_x:0, _y:0});

       

           btn_Reset.onRelease = function():Void

           {

                xfa.host.resetData("radioGroupQ1"); //this resets my radio buttons in "Q1" frame

                gotoAndPlay("Begin");

           }

      }

       

      //Once I return to "Begin" frame, my variables are reset to their initial value since that's where I originally defined them, and I go to "Q1" because that's what the code in frame "Begin" says.  Here is where I click on rbtn_YESQ1 again and even though the button does fill in, it does not attach btn_Reset to the stage as defined by rbtn_YESQ1.onRelease function.

       

      What am I doing wrong?

        • 1. Re: Radio buttons not working after resetting
          kglad Adobe Community Professional & MVP

          that's not the way you code a radiobutton.  you should be using a click listener.  check the flash help files.

          • 2. Re: Radio buttons not working after resetting
            atrzebunia Level 1

            kglad, I took your suggestion and revised the code for the radio buttons, but I still get the same result.  Initially when I click on rbtn_YESQ1, the btn_Reset is attached to stage and is functioning.  So when I click on btn_Reset, btn_YESQ1 and btn_NOQ1 are reset, and the playhead goes to frame "Begin".  Code in frame "Begin" moves the playhead to frame "Q1" where my radio buttons are located and have been reset.  I click on rbtn_YESQ1 again and it does not attach btn_Reset on the stage.  Why?  Here's my revised code based on your suggestion.

             

            //Frame "Begin"

            gotoAndStop("Q1")  //I also define my variables in frame "Begin"

             

            //Frame "Q1"

            yesListener = new Object();

            yesListener.click = function (evt)

            {

                 attachMovie("btnReset", "btn_Reset", 1, {_x:0, _y:0});

             

                 btn_Reset.onRelease = function():Void

                 {

                      xfa.host.resetData("radioGroupQ1"); //this resets my radio buttons in "Q1" frame

                      gotoAndPlay("Begin");

                 }

            }

             

            rbtn_YESQ1.addEventListener("click", yesListener);

             

            //I have the same code below for btn_NOQ1

            noListener...

            • 3. Re: Radio buttons not working after resetting
              kglad Adobe Community Professional & MVP

              what are you doing to remove the first btn_Reset?

              • 4. Re: Radio buttons not working after resetting
                atrzebunia Level 1

                To remove btn_Reset, all I'm doing is returning the playhead to frame "Begin."  There is nothing on frame "Begin" other than code, gotoAndStop("Q1"); which is where all my code for the buttons is located.  See the image below.

                image1.jpg

                • 5. Re: Radio buttons not working after resetting
                  kglad Adobe Community Professional & MVP

                  that wouldn't cause btn_Reset to be removed.  is there something else being added to depth 1?

                  • 6. Re: Radio buttons not working after resetting
                    atrzebunia Level 1

                    Well, I omitted this portion of my code from the thread b/c I wanted

                    to keep it short, but in reality, btn_Reset is attached to an empty movieclip that exists in frame "Q1".  So the code to attach btn_Reset is:

                     

                    ...first part of listener code...

                    {

                         mc_EmptyBtnReset.attachMovie("btnReset", "btn_Reset", 1, {_x:0, _y:0});

                         mc_EmptyBtnReset.btn_Reset.onRelease = function():Void

                         {

                              //btn_Reset actions...

                         }

                    }

                     

                    So, now when I return the playhead to "Begin" and "Begin" moves the playhead to "Q1", there is nothing in mc_EmptyBtnReset, so on click of rbtn_YESQ1 or rbtn_NOQ1, once again mc_EmptyBtnReset should attach btn_Reset at depth 1.  Correct?

                    • 7. Re: Radio buttons not working after resetting
                      kglad Adobe Community Professional & MVP

                      yes.

                       

                      so, the problem must be xfa.host.resetData("radioGroupQ1");

                       

                      what's that function doing?

                      • 8. Re: Radio buttons not working after resetting
                        atrzebunia Level 1

                        I found it online and it's supposed to reset my radio buttons to the original state, i.e. as if they've never been clicked.  Since posting this thread, I actually replaced this function with:

                         

                        btn_YESQ1.selected = false;

                        btn_NOQ1.selected = false; //and then the playhead moves to "Begin"

                         

                        I even removed the function to reset these radio buttons all together, since moving the playhead to "Begin" should reset them anyway, correct?  At least that's what's happening, except that when I click on the radio buttons again, none of their actions fire.

                        • 9. Re: Radio buttons not working after resetting
                          kglad Adobe Community Professional & MVP

                          show the actual code you're using.


                          • 10. Re: Radio buttons not working after resetting
                            atrzebunia Level 1

                            Here's the full code for the radio buttons:

                             

                            ////////////////////////////////////

                            ////Code in frame "Q1"////

                            ////////////////////////////////////

                             

                            //rbtn_YESQ1 code

                            yesListener = new Object();

                            yesListener.click = function (evt)
                            {
                                mc_EmptyReset.attachMovie("btnReset", "btn_Reset", 1);
                                mc_EmptyReset.btn_Reset.onRelease = function():Void
                                {
                                    //Places "Reset Confirmation" window on top
                                    attachMovie("mcResetConfirmation", "mc_ResetConfirmation", getNextHighestDepth(), {_x:24.0, _y:56.0});
                                   
                                    resetConfirmationTween = new Tween(mc_ResetConfirmation, "_alpha", easeNone, 0, 100, .5, true);
                                   
                                    mc_ResetConfirmation.btn_No.onRelease = function():Void
                                    {
                                        mc_ResetConfirmation.btn_No.enabled = false;
                                        mc_ResetConfirmation.btn_Yes.enabled = false;
                                       
                                        resetConfirmationTween.yoyo();
                                        resetConfirmationTween.onMotionFinished = function():Void
                                        {
                                            removeMovieClip(mc_ResetConfirmation);
                                        }
                                    }
                                   
                                    mc_ResetConfirmation.btn_Yes.onRelease = function():Void
                                    {
                                        mc_ResetConfirmation.btn_No.enabled = false;
                                        mc_ResetConfirmation.btn_Yes.enabled = false;
                                       
                                        resetConfirmationTween.yoyo();
                                        resetConfirmationTween.onMotionFinished = function():Void
                                        {
                                            removeMovieClip(mc_ResetConfirmation);
                                            gotoAndPlay("Begin");
                                        }
                                    }
                                }

                            }

                             

                            rbtn_YESQ1.addEventListener("click", yesListener);

                             

                            //Same code as above btn_NOQ1

                            noListener = new Object();

                            noListener.click = function (evt)

                            {

                                 //same code as above...

                            }

                             

                            rbtn_NOQ1.addEventListener("click", noListener);

                             

                            ////////////////////////////////////////

                            ////Code in frame "Begin"////

                            ////////////////////////////////////////

                             

                            gotoAndStop("Q1");

                            • 11. Re: Radio buttons not working after resetting
                              kglad Adobe Community Professional & MVP

                              your problem is caused by a failure to allow enough time for your component (radio button) to "re-initialize".  i'll bet that if you delay that gotoAndStop() in "Begin", you'll have no problem.

                               

                              to test, replace your code in "Begin" with

                               

                              setTimeout(f,100);


                              function f(){

                              gotoAndStop("Q1");

                              }

                              • 12. Re: Radio buttons not working after resetting
                                atrzebunia Level 1

                                Brilliant!  That worked.  Who would've thought.  Thanks for all your help, kglad!

                                • 13. Re: Radio buttons not working after resetting
                                  kglad Adobe Community Professional & MVP

                                  yes, that's a hard one.

                                   

                                  and, you're welcome.