Open the movie 22beatboxnoscripts.fla.
There are three columns of buttons. The first column is for the drum sounds. Select the first drum button and see that its Click Handler is set to buttonSound. In fact, each CheckBox and PushButton component has the Click Handler buttonSound.
Where they differ, however, is their names. The drum check boxes are named drumSwitch1, drumSwitch2, and drumSwitch3. The three bass buttons are named bassSwitch1, bassSwitch2, and bassSwitch3. The three push buttons are named hitSwitch1, hitSwitch2, and hitSwitch3.
This entire movie works with only two functions. The first is an advanced version of the playSound function from earlier in the hour.
It uses four parameters. The first is a true or false value that determines whether the sound is supposed to start or stop. The second is the name of the variable to use as the sound object. The third is the name of the sound from the Library. The last parameter is whether the sound is supposed to loop.
Each of the nine components in the movie calls soundButton. This calls playSound in one of nine different ways, depending on the component clicked. It uses getValue() in many cases to determine whether the check box has been clicked on or off.
Try the sample movie. You can see the finished product as 22beatbox.fla.
Taken From: Sams Teach Yourself Flashâ„¢ MX ActionScript in 24 Hours


Recent Comments