Skip to main content
Participant
July 22, 2021
Question

Undo button active state

  • July 22, 2021
  • 1 reply
  • 87 views

Hi, I wanted to make a button change color when clicked and remain in that color. 

That worked perfectly with the code 

upState=over.State

 

However, I now want to "undo" this when another button is clicked. 

(The buttons should only remain in the "changed" color for a certain number of frames. 

So every time a button is clicked, only the button that was just recently clicked will be in the changed color.

 

Is there an efficient way to solve this? 

 

Thanks! 

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 22, 2021

if you have n buttons named b0, b1, ..., bn-1

 

for(var i: int = 0; i < 3; i++) {
this["b" + i].addEventListener(MouseEvent.MOUSE_DOWN, downF);
this["origUpState"+i] = this["b"+i].upState;
}

function downF(e: MouseEvent): void {
for(var i: int = 0; i < 3; i++) {
this["b" + i].upState = this["origUpState"+i];
}
e.currentTarget.upState = e.currentTarget.overState;
}