Sounds can be applied to the Up, Down, and Over states of a button directly. However, you can also do it using ActionScript by using the "attachSound" method.
First, create a button symbol. This can just be a simple rectangle for testing purposes.
Drag the button from the library onto the stage and give it an instance name of "soundeffectBtn".
Import the sound file you will be attaching to the library. Right-click on it, in the library, and choose Linkage. Give it the identifier name "blip".
Create a new layer above your button layer and click on Frame 1. Hit F9 to bring up the Actions Panel.
Type in the following ActionScript:
//attach the sound to the btn, so when the btn is pressed //a.k.a - it's down state the sound will play soundeffectBtn.onPress = function () { btnBlip = new Sound (); btnBlip.attachSound ("blip"); btnBlip.start(); }
Understanding the ActionScript
The first line is assigns the soundeffectBtn (the button's Instance Name) to an "onPress" event. When this happens the function will be carried out between the brackets.
"btnBlip" is just a variable name - I called have named it Spongebob if I wanted to.
btnBlip = new Sound (); // pretty self-explanatory
btnBlip.attachSound ("blip") // attach the sound blip (remember that's our linkage identifier) to the btnBlip variable.
btnBlip.start(); // play the sound when the button is pressed