Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash toggle button

I need a button in Flash/AS3 that toggles between on and off. So I was glad to see that the Button class has the toggle property that lets me have that behavior. I was less happy to see that what I get when I make something a "button" in the Flash file is an instance of SimpleButton class, which does not have that option.

Is there a way to either get a Button instance from the .fla, or get the SimpleButton to behave as a toggle?

like image 911
Sietse Avatar asked Mar 13 '26 13:03

Sietse


1 Answers

Here's how I coded my way around this:

private buttonState:Boolean;

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

private function clickEvent(e:MouseEvent){
    buttonToggle(e.target);
}

I didn't put the code in the clickEvent function, because this allows me to toggle the button from elsewhere in the code.

like image 172
Sietse Avatar answered Mar 16 '26 01:03

Sietse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!