Author: Matt Slaybaugh
Date: October 12, 2006
In this tutorial, you will learn about how sounds are incorporated into a Flash applet by changing the sounds used in the Fly Catcher game. Using sounds in Flash is easy. You first need to import a sound file into the library, then initialize the sound in Actionscript, and then associate the sound playing with an event.
- Flash 8
This software is licensed to the public under the CC-GNU GPL.
Using sounds in Flash is easy You first need to import a sound file into the library, then initialize the sound in Actionscript, and then associate the sound playing with an event.
You can find many free sounds on the Web. Simply type flash sound into any search engine and you will find many free sound libraries.
Flash accepts many sound formats, but files ending with .wav or .mp3 are the most common.
- Using your Web browser, visit http://www.flashkit.com/soundfx/
- Download one of the sounds to your desktop.
- From the File menu in Flash, select Import -> Import to Library
- Right-click the new sound file and select Linkage...
- In the pop-up window, click Export for ActionScript. Note the name in the Identifier: window. It will be the name of the sound file used in the code below
- In the timeline, find the bottom layer, named scripts, and click frame 5.
- In the Actions panel, find line 25. You should see code that looks like this:
fly_bite = new Sound();
- In the second line, replace buzz.wav with the name of the sound you imported.
- Further down the code, around line 71 you should see code that looks like this:
- This is the code that plays the sound every time a fly comes close enough to the frog to bite it. You do not need to change this code.
- Save the file and test it. (ctrl-enter)
- Add more sounds—Note how sounds are added, initialized in the main script, then activated when an event occurs