Sonify Your Web Site: Add Backing Music
You can use the FlashSound API to add backing music to your Web site as well as interactive sound. Backing music is a great way to add ambiance and character to a site. Flash has two kinds of sound playback, stream and download. There are pros and cons to using either downloaded or streamed sounds. Be sure to consider these before deciding on a method of delivery.
Autostart Download Sounds
- A stream sound plays as it loads. Therefore, a user does not have to wait long to hear sound. However, the disadvantage is that bit rates of 32kbps or less, (required for steady streaming on a 56kbps modem), often produce low quality music or sound. In addition, users will experience breaks in the sound if their data transfer rate cannot keep up with the stream.
- Downloaded sounds do not begin to play until they are fully loaded. Therefore, you should use this method only with sounds that fit into small files so that users don't have to wait too long for the sound to start. The advantage of downloaded sounds is that they don't break up over slow connections and (because there's no bandwidth limitation during playback) can be of higher quality. You can achieve a reasonable balance between sound quality and download time with higher bit rates (32kpbs or more) if your sound has a short duration (less than 5 seconds).
To create an Autostart sound, change the ActionScript
and 16).Play a Download Sound After Page Load
Sometimes you need to play backing music after the page layout is in place. In this case, do not use the Autostart approach because with that approach your sound may start playing before the layout is rendered. Instead, use the window.onload event to play backing music. With this technique, the browser waits until your SWF file and all the graphics and HTML on the page are fully loaded before playing the music. The following code is similar to the onMouseover code on the previous page, but in this case, you use the onLoad event handler in the body tag to trigger the TGotoAndPlay( ) method.
Stop Background Music
<body onLoad =
You can stop an onLoad or Autostart sound with the TGotoAndPlay("targetpath","stop") method. Specify the target path and stop frame of the movie clip containing the sound you want to stop. For example:
Looped Backing Music
Stop Background Music
To loop a sound in Flash, select your sound on its timeline and enter a value between 2 and 999 in the Sound Panel loop entry box. Looping a sound does not change the size of your SWF file (see Figure 17