Use Sound in Flash: Change "Fly Catcher" sounds

Author: Matt Slaybaugh
Date: October 12, 2006
Level: Beginner

Summary

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.

Experience Needed
Software
  • Flash 8
Files — Flycatcher.zip (411 KB)
  • flycatcher.fla
License — "Fly Catcher" (c) 2007, World Wide Workshop Foundation

This software is licensed to the public under the CC-GNU GPL.

Description
Change the sounds in the 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.

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.

  1. Using your Web browser, visit http://www.flashkit.com/soundfx/
  2. Download one of the sounds to your desktop.
  3. From the File menu in Flash, select Import -> Import to Library
  4. Right-click the new sound file and select Linkage...
  5. 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
  6. In the timeline, find the bottom layer, named scripts, and click frame 5.
  7. In the Actions panel, find line 25. You should see code that looks like this:
    fly_bite = new Sound();
    fly_bite.attachSound("buzz.wav");
  8. In the second line, replace buzz.wav with the name of the sound you imported.
  9. Further down the code, around line 71 you should see code that looks like this:
    fly_bite.start();
  10. 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.
  11. Save the file and test it. (ctrl-enter)

More Project Ideas
  • Add more sounds—Note how sounds are added, initialized in the main script, then activated when an event occurs