7 Replies Latest reply on May 19, 2017 11:12 AM by Paul Darky

    How to keep the down state of a button?

    liolee08 Level 1

      I'm not too experienced with Flash... I'm using Flash CS5 on Windows 7.

       

      I can't figure out how to make a button stay in its down state when it's clicked, and then go back to its up state when another button is clicked?

      I'm using buttons, not movie clips.

       

      Any help is welcomed!

       

      Brigitte

        • 1. Re: How to keep the down state of a button?
          Ned Murphy Adobe Community Professional & MVP

          Look into the Properties of the SimpleButton class, and have a look  at the file I linked in this posting: http://forums.adobe.com/thread/676547?tstart=0

          1 person found this helpful
          • 2. Re: How to keep the down state of a button?
            liolee08 Level 1

            I thought I could copy your AS from your file, but I realized that your buttons are identical, mine are not. And since I don't know anything about AS, I don't know how to modify it to work with my two different buttons.

             

            I've never done AS - I only do simple tweens in Flash. But thank you for trying to help this inexperienced newbie.

             

            Brigitte

            • 3. Re: How to keep the down state of a button?
              Ned Murphy Adobe Community Professional & MVP

              No. in most cases just copying code won't get you where you want to go, but a little time spent trying to understand it and trying things can usually work wonders and result in a feeling of accomplishment.

               

              In that other posting, that person is trying to invent a new/fourth button state, so the hitTestState was used as a placeholder for defining that state's graphics.  The problem in that case was that all frames of the button are used up, so the upState gets lost when it assumes the disabled state, and some other resource is needed to reset it to be the up state graphics.  That other resource could just as easily be an object that gets assigned as the upState.

               

              In your case, you don't have that problem.  You already have the two states defined in the button's regular frames, so you just need a placeholder for the state that will be getting changed (the upState).  So if you copy your Up frame of the button to the Hit frame, you then have a place to go to when you want to restore the upState.  So the code in the example I pointed to would need to be adjusted so that the button changes to the downState when it is clicked and is reset to the hitTestState when the time comes for that (when the other button is clicked in that example).  Essentially, the change in the code would be...

               

              btn1.addEventListener(MouseEvent.CLICK, disableIt1);

              function disableIt1(evt:MouseEvent):void {
              btn2.upState = btn2.hitTestState;
              btn1.upState = btn1.downState;
              btn2.mouseEnabled = true;
              btn1.mouseEnabled = false;

              }

               

              similar for btn2

              • 4. Re: How to keep the down state of a button?
                liolee08 Level 1

                Thank you soooooo much!  You have no idea how much this means to me!!! It works!!!

                 

                Thank you for taking the time to explain this in details. It's with people like you that people like me can learn!

                 

                You just made my week!

                 

                Have a great day! and thank you again!

                 

                Brigitte

                • 5. Re: How to keep the down state of a button?
                  pablopi

                  Hi Ned,

                   

                  What about when you need to use more than 10 buttons?

                   

                  Best.

                  • 6. Re: How to keep the down state of a button?
                    ClayUUID Adobe Community Professional

                    What about it?

                    • 7. Re: How to keep the down state of a button?
                      Paul Darky Level 1

                      Hi Clay,

                       

                      I have a movie clip which works as a LIST with almost 40 buttons on it. Each button is to add a movie clip from the library to the stage. After the added movie clip is shown and removed the user goes back to the LIST and I need a way to let him know which was the last button he clicked.

                       

                      The code given by Ned makes me think I would need to integrate all the 40 button´s instance names to it and I wonder if there is an easier way to do it. Or if there is a component to do this?

                       

                      All I need is to show which was the last button clicked.

                       

                      Thanks.