We help IT Professionals succeed at work.

How can i make a button stay in the down state until another is clicked?

How can i make a button stay in the down state until another is clicked?
Watch Question

Try using the ToggleButtonBar for navigation it comed directly with that functionality.

Or you use the toggle property of the Button component (have a look at this example):
Ups ... sorry ... just noticed you were talking about plain old flash and not flex. Try this:


That is great for sound Chris but we just want to overstate to stay in colour until another button is clicked. What code would you employ?
well couldn't you just set the color in the onclick handler and have the handler of every button reset the color of the other buttons? I know this is not really extendable, but it should do the trick.


Hi Chris
Thanks for your response we may come back to you at a later date.
1) put your buttons in an array.

2) in the onClick of each button call an isolated function e.g. resetButtons();

3) inside resetButtons, loop the array changing all buttons back to the original state.

4) Then change the one clicked to the down state.

Its more extend-able because you just need to add future buttons to your array.
This answer will probably be overkill, but just to add my two cents. For what you are describing the State Machine design pattern will work wonders. It will keep your code nicely encapsulated, object-oriented and will simplify future changes.

Of course, you have to be committed to using OO best practices, otherwise, like I said, this will be overkill.

But, if you want to expand your development horizons, here's some recommended reading:


Here's an Adobe tutorial that makes the buttons play video, but if you ignore that part you can concentrate on their use of the State Design Pattern to do what you want to do (keep the button pressed until the next one is pressed)

And here's the definitive resource for Flash, ActionScript 3 and Design patterns:

Best of luck! Don't shy away from taking your coding skills to the next level!



Thanks very much guys.