8 Replies Latest reply on May 15, 2008 12:29 PM by Ned Murphy

    how to disable other buttons when a button clicked

    roughbern
      I built an app that has 5 buttons that each can play a movieclip. How do I prevent someone playing a second or third... movieclip after one has begun to play?

      I have played with the enable property but I don't seem to be able to get it right. The buttons are on the parent stage, not in the movieclip. Their instance names are mycase1_btn, mycase2_btn, mycase3_btn, mycase4_btn, mycase5_btn.
        • 1. how to disable other buttons when a button clicked
          Ned Murphy Adobe Community Professional & MVP
          I don't know if you missed seeing my reply to your first posting of this, or tried it and couldn't get it to work, but it will work (it's written for your code). If you have a problem getting it to work, just ask for more help with it:

          One way to deal with disabling sets of buttons is to have a function that enables/disables them all, as in...

          function enableBtns(truefalse){
          for(i=1; i<6; i++){
          this["mycase"+i+"_btn"].enabled = truefalse;
          }
          }

          Then, within the button functions, you call the function to disable them all along with whatever you do to get the movelip playing...

          on(release){.... // depends how you code your buttons

          // start the movieclip....

          // disable the buttons
          enableBtns(false);

          }

          And when the movieclip finishes playing you need to have the buttons enabled again... which you can have in the last frame of the movieclip.

          _parent.enableBtns(true);
          • 2. Re: how to disable other buttons when a button clicked
            roughbern Level 1
            I did see your earlier reply but couldn't get it working. I will look at your latest reply and maybe I can get it working. I appreciate the help.
            • 3. Re: how to disable other buttons when a button clicked
              roughbern Level 1
              where should I put the code you suggest, in the movieclip on the actions layer?
              • 4. Re: how to disable other buttons when a button clicked
                Ned Murphy Adobe Community Professional & MVP
                The function would go in the timeline that has the buttons, not the same layer, just the same timeline where the buttons exist.

                The on(release)... code I provided above would be attached to the buttons. To do that, you click on the button itself on the stage, and then enter that code in the actions panel. An alternative that could go where you put the function code is using...

                mycase1_btn.onRelease = function(){

                // start the movieclip.... whatever you do for that

                // disable the buttons
                enableBtns(false);

                }

                The latter may be preferred because it is more readily visible when hunting things down.

                The last line... _parent.enableBtns(true);
                could be placed in the last frame of the movieclip that is playing (or whatever else might be detecting the end of the movieclip).
                • 5. Re: how to disable other buttons when a button clicked
                  roughbern Level 1
                  I appreciate the help.

                  I put this code on the mycase3_btn button

                  function enableBtns(truefalse){
                  for(i=1; i<6; i++){
                  this["mycase"+i+"_btn"].enabled = truefalse;
                  }

                  // disable the buttons
                  enableBtns(false);

                  }
                  }

                  on(release)
                  {
                  MCCase3b.play();
                  }

                  Also I have this code on the last frame on the actions layer of the movieclip.

                  _parent.enableBtns(true);
                  gotoAndStop(1);

                  I tested the app and got this error message referring to the last frame of the actions layer on the movieclip.
                  Description =1120: Access of undefined property _parent.
                  Source =_parent.enableBtns(true);

                  I probably have the syntax off, but that is what I have. What do you suggest?

                  • 6. Re: how to disable other buttons when a button clicked
                    Ned Murphy Adobe Community Professional & MVP
                    That function should go on the timeline, not on the button, and it should not include the call to itself in the function.... that will go on forever so the movieclip might enable the buttons for a micrsecond, but the function will still be running telling all the buttons to be disabled.

                    The code on the button should be..

                    on(release)
                    {
                    MCCase3b.play();
                    enableBtns(false);
                    }

                    I can't be sure what the movieclip's _parent issue is since that's a legit call, provided the movieclip is a child of the movie that holds the enableBtns function.
                    • 7. Re: how to disable other buttons when a button clicked
                      roughbern Level 1
                      Thank you very much!! I obviously am new to all but the simplest Actionscript. I learned that functions go on frames etc.

                      My app buttons work correctly now.
                      • 8. Re: how to disable other buttons when a button clicked
                        Ned Murphy Adobe Community Professional & MVP
                        You're welcome. There's plenty left to learn, so take your time and have fun with it.