Building a better button

The built in Flash button is a very useful control and can be used in many cases as it comes out of the box. But there are times when you want to add something to the button's functionality, or possibly, to its action. You may want the button's action to be more dramatic, you may want to show the motion between one state and another. You may want the button to latch when it is used. You may want any given button to work in concert with one or more other buttons, like in a radio button set.

Here are two examples. In the first, the button is actually a movieclip. Each state of the movieclip is set in the movieclip's timeline. The various mouse events are connected to functions which tell the playback head in this movieclip to play different sections of the clip.

As it is now, with these three buttons, each button will latch in the down position. Selecting another button will release the current button and latch the new button. Reselecting the current button will unlatch that button. You can add as many additional buttons as you like and just add the button instance code the existing code. You will, of course, have to add some useful code to have these buttons do some actual work.

This second example gives you the same result. It just uses a different mechanism to get there. The animation for each button is the result of a tween. In this example I'm using tweens generated by the TweenMax library. There are many, many, tween libraries available for use with Flash. I like this one. You can download it from here:

You can download the original .fla files for each of these movies and use the contents if you like.

download the source files