Flash sound button tutorial
Download the source Flash sound button.zip
In this tutorial we will learn how to Add sounds to a button via ActionScript, this avoiding the need to put them manually in each button.
Step 1
Open a new Flash document. Call the first layer button.
- Using the Oval tool (O) draw a circle on stage. You don’t have to draw a complicated button like I did, the purpose of this tutorial is to show how you can attach sounds dynamically.
- Select the circle and press F8 to convert it to a button. In the Convert to Symbol dialog box that appears, choose Button as type and call it whatever you like – button 1, blue button, green button, etc.
- Now, it is important to give your button an instance name. Otherwise, you wouldn’t be able to control the button with ActionScript.
So, with the button still selected on stage, go to the Properties panel. On its left side, in the Instance name field type button01 and press enter Ex. Fig 1.
Fig 1
Step 2
In this step we will import a sound to library and preparing it for use by ActionScript.
- Import a sound for your button in Flash. If you don’t have one handy, download the WAV sound for this lesson. Load the sound into Flash by selecting File > Import > Import to Library, finding your WAV sound file and clicking Import to Library.
- Open the library (Window > Library), right-click (Mac users CTRL+CLICK) on the sound file you just imported and select Linkage from the menu. The Linkage Properties panel will appear.
In the Identifier field, type buttonSound01. This is the identifier name by which you will call and use the sound with ActionScript. example Fig 2
Flash will by default show the filename of the sound in the identifier field (effect1.wav in my case). Remember that you should use no special characters for the Identifier name – follow the same rules you use for naming movie clips, buttons and variables. That means no special characters (!#$%.,/) should be used, start the name with a letter and don’t use any spaces.
Also, check the Export for ActionScript and Export in first frame boxes. What do they mean?
The first one is clear: by checking it, you say to Flash “Listen, I want this sound to be available for dynamic manipulation via ActionScript”. Flash says “As you say, mylady/mylord”.
The second one, Export in first frame, makes the sound load before any other elements of your movie. That means the sound will load before the first frame of your movie’s timeline and anything it contains. So, if your sound has a big file size, visitors to your site will get a blank screen until it loads completely.
If you leave this box unchecked, the sound won’t load immediately and your users might not hear anything at all if they clicked the button and the sound hasn’t loaded yet.
You leave the box checked and you solve the problem by loading your movie with sounds into another movie.
Step 3
Make a new layer and call it actions. Select its first frame and open the Actions panel (Window > Actions). Example Fig 3.
Step 4
Enter the following code in the Actions panel:
clickSound = new Sound();
clickSound.attachSound(“buttonSound01″);
button01.onRelease = function () {
clickSound.start();
}
This is it , now you can test it.



[...] Learn to do the same thing with actionscript how to add sound to buttons dynamically with actionscript [...]
[...] Originally posted here: Flash sound button tutorial | Flash tutorials | Flash video … [...]
[...] Flash sound button tutorial | Flash tutorials | Flash video … [...]
[...] original here: Flash sound button tutorial | Flash tutorials | Flash video … Share and [...]
[...] Flash sound button tutorial | Flash tutorials | Flash video … [...]
[...] Flash sound button tutorial | Flash tutorials | Flash video … [...]
[...] Flash sound button tutorial | Flash tutorials | Flash video … [...]
Nice simple way to control sound with simple buttons. Thanks!