0
votes

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! =)

3
But how do I swap the states back when I hit a new button? - Stian Berg Larsen
I just stored each state at init(); and cleared the toggle each time I click a button.. (cant answer my ownquestion yet.. :P) - Stian Berg Larsen
Seems like the simplest thing is to reskin a RadioButton component - Amy Blankenship

3 Answers

2
votes

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.

1
votes

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;
    }
}
1
votes
private function onClick(event:MouseEvent):void {
    if(prevSelected) {
        //change the skin of selected 
    }
    //save the current selected button 
    //change the current selected button skin
}