Adding background music to Flash sites

There are two methods for adding a sound to a document in Flash: a) using the library and b) linking at runtime.

A) Using the Library 

  1. Import the sound file into the library.
  2. Add a layer for the background sound.
  3. Use the property panel to select the sound file.
  4. Set Sync to either Event or Stream.

“There are two types of sounds in Flash: event sounds and stream sounds. An event sound must download completely before it begins playing, and it continues playing until explicitly stopped. Stream sounds begin playing as soon as enough data for the first few frames has been downloaded; stream sounds are synchronized to the Timeline for playing on a website.”

Streaming the background sound is a better option, especially if the sound file is large.

  1. Add as many frames as needed to play the sound.

Disadvantages:

  1. Since the sound file should be imported into the Flash project, the size of the SWF will be impacted accordingly. This in turn impacts the download time for the site, possible resulting in an unacceptable performance.
  2. The sound file may require more or less frames than the rest of the layers.

Advantages:

  1. You can control the number of times the sound repeats
  2. You can add effects to the sound like Fade In, Fade Out, Left Channel/Right Channel and Fade Left to Right/Fade Right to Left.
  3. You can choose between Event and Stream.

b) Linking at Runtime

An alternative to adding the sound file to the Flash project, is to link to an external sound file from the Flash project (or loading sound at runtime). This method has the advantage of keeping the SWF file size smaller and the performance better.

To link to an external sound file use the following ActionScript:

var background_music:Sound = new Sound();

background_music.loadSound(”sound_file.mp3″, true); 

See the loadSound method of the Sound object for more details.

 

 

1 Comment »

  1. Jason said,

    February 16, 2008 @ 11:03 pm

    Thanks a lot, that really helped me out! Those audio files can really slow things down, if you don’t know what you’re doing!

RSS feed for comments on this post · TrackBack URI

Leave a Comment