You can add sound to your movie at authoring time by importing a sound into a layer of a timeline. Furthermore, you can set the volume and pan for that sound at authoring time. However, to control the sound during runtime, you must use a Sound object. With a Sound object, you can programmatically control sounds in ways that you cannot at authoring time, including:
Attaching sounds from the library
Loading external MP3s
Starting and stopping playback based on user input, server responses, or other runtime events
Adjusting the sound panning and volume based on user input, server responses, or other runtime events
Controlling the playback position of a sound (such as user-controlled seek, fast-forward, and rewind)
Accessing the sound's total duration
Reading song data (artist name, title, etc.) from ID3 tags (for loaded MP3s only)
Sound objects control the sounds that exist within a movie clip?whether those sounds were placed within the movie clip at authoring time or attached or loaded into the movie clip at runtime using ActionScript. It is possible to place multiple sounds within a single movie clip; however, doing so is poor practice because it prevents you from controlling the sounds individually. Rather, in most cases, you should create separate movie clips for each sound and create a separate Sound object to target each movie clip.
The hierarchy of movie clip timelines also comes into play with sounds. The volume and panning for sounds in parent movie clips affect the perceived volume and panning of nested sounds. For example, if you set the volume to 50 for a Sound object targeting _root, the playback of all sounds in the movie will be at half their own volume settings.
There are a few things to keep in mind when using sounds in Flash. First of all, Flash can play only up to eight sounds simultaneously. So make sure you plan accordingly.
This chapter looks at sounds that are added to a movie programmatically. When you add sounds programmatically, Flash does not provide a way to automatically synchronize the animation to the sound. For basic information on using and synchronizing sound in Flash, see Help Using Flash Adding Sound. See Recipe 15.3 for loading an external MP3 sound. Also refer to Chapter 14 for recipes dealing with audio as it relates to the FlashCom server.