0

How would I do this?

I've got tree buttons. Only one is supposed to be "selected" at a time. They play different animations.

What I need, is to set the button (which has different bg color depending on its over, up and down state) to it's down state.

Simply put; I need to freeze the button in it's down-state when it's clicked. And when I click one of the other buttons, it's supposed to return back to its normal state, and the new button is to be frozen in it's down state.

I'm using Flash, AS3..

Thanks! =)

Stian Berg Larsen
  • 543
  • 2
  • 10
  • 29

3 Answers3

2

Simply stated:

When you set the upState = downState to show that an item was selected, you have lost the ability to go back to the original upState. So it's a very simple matter to store the upState as a variable so that you can ALWAYS go back to it.

//capture upstate as a variable

var buttonUpVar:DisplayObject = button.upState;

//button stays selected or in downState when released.

button.upState = button.downState;

//deselect button by going back to original upState

button.upState = buttonUpVar;

Done, with minimal code.

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
1

Try this code that I adapted from the solution you linked to.

private toggledButton:SimpleButton;

private function buttonToggle(button:SimpleButton){
    var currDown:DisplayObject = button.downState;
    button.downState = button.upState;
    button.upState = currDown;
}

private function clickEvent(e:MouseEvent){
    if (toggledButton != e.target) {
        buttonToggle(e.target);
        if (toggledButton)
            buttonToggle(toggledButton);
        toggledButton = e.target;
    }
}
sch
  • 27,436
  • 3
  • 68
  • 83
1
private function onClick(event:MouseEvent):void {
    if(prevSelected) {
        //change the skin of selected 
    }
    //save the current selected button 
    //change the current selected button skin
}
Triode
  • 11,309
  • 2
  • 38
  • 48