• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Oct 15, 2017 Oct 15, 2017

Copy link to clipboard

Copied

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!

Views

316

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 15, 2017 Oct 15, 2017

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.upState,buttonA.overState,buttonA.downState]);  // maintains a record of states of all buttons

buttonA.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.upState = buttonA.overState;  // if that's what you want

}

}

}

Votes

Translate

Translate
Community Expert ,
Oct 15, 2017 Oct 15, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 15, 2017 Oct 15, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2017 Oct 15, 2017

Copy link to clipboard

Copied

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.upState,buttonA.overState,buttonA.downState]);  // maintains a record of states of all buttons

buttonA.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.upState = buttonA.overState;  // if that's what you want

}

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 15, 2017 Oct 15, 2017

Copy link to clipboard

Copied

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.upState, NameButton.overState, NameButton.downState]); // maintains a record of states of all buttons

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

NameButton.addEventListener(MouseEvent.MOUSE_OVER, ovefF);

NameText.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.overState = NameText.overState; // if that's what you want

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

}

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2017 Oct 15, 2017

Copy link to clipboard

Copied

var buttonA:Array=[namgeButton,nameText];

var buttonStateA:Array=[];

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

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

buttonA.addEventListener(MouseEvent.MOUSE_OVER,ovefF);

buttonA.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.upState = buttonStateA[1];  // if that's what you want

}

}

}

function outF(e:MouseEvent):void{

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

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

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 15, 2017 Oct 15, 2017

Copy link to clipboard

Copied

Thank you! I will give that a shot.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2017 Oct 15, 2017

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines