7 Replies Latest reply on Oct 15, 2017 3:00 PM by kglad

    A button's "down" and "hit" state includes changes to other buttons

    ks67641067

      Hi there -

       

      I thought I remembered a simple way to cause one button to change other buttons' down and hit states - but I can't seem to make it work easily. I have a series of buttons on the stage: button A, B, C, D, and so on. I want to, effectively, link multiple buttons. So if I hit Button A, I want Buttons C, D, and Q to change their states to their hit states. If I roll over button A, I want those buttons to change to their rollover states.

       

      Is there a simple way to get that done?

       

      Thank you in advance for any help you can offer!

        • 1. Re: A button's "down" and "hit" state includes changes to other buttons
          kglad Adobe Community Professional & MVP

          simple buttons have upState,downState and overState properties you can use to change a button's display.

          • 2. Re: A button's "down" and "hit" state includes changes to other buttons
            ks67641067 Level 1

            Thank you! Yes, I understand how to make one button look different in up, down and over states. But my question is how I can make one button make another button's state change as well as its own.

            • 3. Re: A button's "down" and "hit" state includes changes to other buttons
              kglad Adobe Community Professional & MVP

              again, use those button states.  eg,

               

              var buttonA:Array=[you buttons];

              var buttonStateA:Array=[];

              for(var i:int=0i<buttonA.length;i++){

              buttonStateA.push([buttonA[i].upState,buttonA[i].overState,buttonA[i].downState]);  // maintains a record of states of all buttons

              buttonA[i].addEventListener(MouseEvent.MOUSE_OVER,ovefF);

              }

              function overF(e:MouseEvent):void{

              for(var i:int=0;i<buttonA.length,i++){

              if(i!=buttonA.indexOf(e.currentTarget)){

              buttonA[i].upState = buttonA[i].overState;  // if that's what you want

              }

              }

              }

              1 person found this helpful
              • 4. Re: A button's "down" and "hit" state includes changes to other buttons
                ks67641067 Level 1

                Ohhh - I misunderstood; thank you.

                 

                I'm pathetic with scripting. Let's say I have two buttons - one is called NameButton, and the other is called NameText. I want an action (hover, click, hit) to be mirrored between the two. If I hover over NameButton, I want NameText to show its hover state too, and vice versa. If I hit NameText, I want NameButton to act as if it were hit as well. I know I've butchered yourcode to an embarrassing degree - would you be willing to show me the correct syntax for that intended experience?

                 

                var buttonName: Array = Name Buttons;

                var buttonStateNameButton: Array = [NameButton, NameText];

                for (var i: int = 0i < NameButton.length; i++) {

                buttonStateNameButton.push([NameButton[i].upState, NameButton[i].overState, NameButton[i].downState]); // maintains a record of states of all buttons

                buttonStateNameText.push([NameText[i].upState, NameText[i].overState, NameText[i].downState]

                NameButton[i].addEventListener(MouseEvent.MOUSE_OVER, ovefF);

                NameText[i].addEventListener(MouseEvent.MOUSE_OVER, ovefF);

                }

                function overF(e: MouseEvent): void {

                for (var i: int = 0; i < Name Button.length, i++) {

                if (i != NameButton.indexOf(e.currentTarget)) {

                NameButton[i].overState = NameText[i].overState; // if that's what you want

                NameText[i].overState = NameText[i].overState; // if that's what you want

                }

                }

                }

                • 5. Re: A button's "down" and "hit" state includes changes to other buttons
                  kglad Adobe Community Professional & MVP

                  var buttonA:Array=[namgeButton,nameText];

                  var buttonStateA:Array=[];

                  for(var i:int=0i<buttonA.length;i++){

                  buttonStateA.push([buttonA[i].upState,buttonA[i].overState,buttonA[i].downState]);  // maintains a record of states of all buttons

                  buttonA[i].addEventListener(MouseEvent.MOUSE_OVER,ovefF);

                  buttonA[i].addEventListener(MouseEvent.MOUSE_OUT,outF);

                  }

                  function overF(e:MouseEvent):void{

                  for(var i:int=0;i<buttonA.length,i++){

                  if(i!=buttonA.indexOf(e.currentTarget)){

                  buttonA[i].upState = buttonStateA[i][1];  // if that's what you want

                  }

                  }

                  }

                  function outF(e:MouseEvent):void{

                  for(var i:int=0;i<buttonA.length,i++){

                  buttonA[i].upState = buttonStateA[i][0];  // if that's what you want

                  }

                  }

                  1 person found this helpful
                  • 6. Re: A button's "down" and "hit" state includes changes to other buttons
                    ks67641067 Level 1

                    Thank you! I will give that a shot.