Home > Articles

  • Print
  • + Share This
This chapter is from the book

Using Sounds

Now that we've imported the sounds into our movie, we can explore how to make them play at the correct times. There's really only one place you can use sounds in Flash: in keyframes. (One exception is adding sounds dynamically with the advanced ActionScripting method for sound objects called attachSound.) If you want a sound to play whenever the user places his or her cursor over a button, you still need to place the sound in a keyframe—it's just a keyframe in the button. Attaching sounds to a button is a little more complex, and we'll cover that in depth in Hour 13, "Making Buttons for Your User to Click."

Now that we know sounds go in keyframes, we need a way to put them there. When you select a keyframe, the Properties panel provides a way to control what sounds play when you reach the selected keyframe. Flash provides other clues for you to "see" where sounds have been placed. For example, if your Timeline is long enough, you'll see a waveform for the sounds being used (as shown in Figure 10.3).

Figure 10.3 The waveform (the picture of the sound) is displayed in the Timeline. This will be helpful when you're trying to synchronize images with specific parts of your sound.

The Properties panel, however, is your best way to see which sounds have been added to which keyframe. But just like any other panel, the Properties panel displays only the sound used in the selected keyframe. Misreading this panel is very easy because it changes when you deselect keyframes. Figure 10.4 looks almost identical to Figure 10.3. However, in Figure 10.4, the Properties panel shows that no sound is being used. When you look closely at the Timeline, there's a waveform displayed but no keyframe selected. Therefore, it's necessary to look at the Properties panel after you've selected a particular keyframe.

Figure 10.4 The Properties panel can be confusing. It only displays (or lets you specify) sounds when a keyframe is currently selected. Here, the keyframe isn't currently selected, so the Properties panel displays nothing.

Sync Settings

After we have the Properties panel reflecting sound for the intended keyframe, we can decide exactly how the sound should play. The most fundamental choice you need to make for each use of a sound is its Sync settings. These control exactly how a particular instance of your sound will play—or, more specifically, the priority of the sound compared to the visual elements in your animation. Before you try them out, see the following list and Figure 10.5 for an explanation of each:

  • Event is the default setting and, generally, the best performance choice, especially for sound effects and other "incidental" sounds. When Event is chosen, sounds will start to play when the keyframe is reached and keep playing until they're done. Event sounds might not coincide with visual elements the same way on everyone's machine. Sounds won't play slower or faster (that would make them sound funny), but a machine with slower graphics performance may take longer to display visual elements. Suppose you have a one-second Event sound and your framerate is 12fps. You would expect that during the sound, 12 frames would be displayed, but a slow machine might only display six frames a second, in which case the sound would finish in one second, as you would expect, but after only six frames have been displayed.

  • Start is almost the same as Event, except that multiple instances of the same sound are prevented. With Event, a sound can be layered on top of itself, similar to singing a "round." Think of Start as playing a sound if it's not already playing.

  • Stop is kind of weird—it's for when you want a specified sound to stop playing. For example, if you import a sound called "background music" and by whatever means have it playing, when a keyframe is encountered with the same sound (background music) set to Stop, just that sound will stop. Any other sounds already playing will continue. This is a bit strange because you use the Properties panel to specify the sound (just like when you want the sound to play), but you're specifying it as the particular sound you want to stop. Think of Stop as "stop this sound if it's playing."

  • Stream causes the sound to remain perfectly synchronized with the timeline. Because, again, you can't have sounds playing slowly if the user's machine can't draw frames quickly enough, Flash will skip frames to keep up. Stream sounds start playing when the first frame is reached and continue to play as long as there is space in the timeline. In other words, if your sound is three seconds long and you're playing at 12fps, the timeline has to be at least 36 frames; otherwise, part of the sound will never be reached. The benefit of this setting is that synchronization will always be the same. If you place a graphic in frame 12, it will coincide perfectly with the first second of your sound. Just remember that when you're using Stream, you have to ensure there are enough frames in the Timeline to accommodate the length of the sound. Finally, Stream sounds are previewed as you "scrub," thus making the process of synchronizing audio to images possible.

Figure 10.5 For each instance of a sound, you must select a Sync setting (via the Properties panel).

The decision as to which Sync setting to use isn't terribly difficult. Event should be used for any short incidental sounds—such as rollover sounds. Actually, I suggest Event for all sounds that don't require critical synchronization. Background music that just plays and loops won't need to be synchronized. Therefore, you should use Event. Start is a perfectly good alternative to Event and will simply prevent the layering of the same sound. For example, suppose you have a row of five buttons. If each button has the same rollover sound and the user quickly moves across all five, an Event sound will play once for each button. If the sounds are short enough, this is probably appropriate. However, if the sounds are quite long, they would become discordant. If you use the Start sync setting, only one instance of the sound would play at a time, regardless of how fast the user moves his or her mouse. Event can be a better choice than Start when a little bit of overlap is okay. Consider a "ding" sound every time a ball bounces on the ground. If you choose Event the ball can bounce a second time and even if the first sound isn't totally finished, it will play again. In any event, Start and Event are good for the majority of sounds you'll play.

Rollover sound is a sound effect that plays any time a user places his or her cursor over a button. You'll learn about this later in Hour 13.

The Stop sync setting is very powerful. It gives you a way to stop specific sounds. Using this method can be a little tricky because it will only stop one sound per keyframe. When you learn about Actions (as you will in Hour 14, "Using ActionScript to Create Non-Linear Movies"), you can insert the "Stop All Sounds" Action to stop all sounds at once. Depending on the situation, this may be appropriate. If you're giving the user the ability to get several sounds going at once, you'll want to learn Stop All Sounds. However, suppose you have one sound playing in the background, and when a tween starts you want a special sound effect to play (and keep playing) until the tween ends. You can put the background sound in an early keyframe and then, in the first keyframe of the tween, place the sound effect and set its sync to Event or Start. In the last frame of the tween, you can put the same sound effect but set the sync settings to Stop. This way, the sound effect will stop at the end of the tween, but the background sound will continue.

Finally, Stream is good for one thing: synchronizing graphics with sound. This is especially useful for character animation where you want a character's lips to synchronize with its voice. When trying to synchronize sounds with images, use the "scrub" technique mentioned earlier, but now with Stream sounds you'll hear the sound as you scrub. Because Stream sounds effectively lock themselves to the Timeline, you probably don't want to change the movie's framerate. For example, a three-second sound will take 36 frames at 12fps. If you do some work and then change the framerate to 24fps, the same three-second sound spans 72 frames! Flash automatically spreads the Stream sound out so that it takes three seconds when you change the framerate, but Flash won't change your graphics, which will now play in 1.5 seconds. See Figure 10.6 for a before-and-after example of changing the framerate after an animation is built.

In spite of this issue, you should stick with a framerate (which, really, isn't anything new—it comes up even if you don't use sounds). Stream sounds remain pretty appealing. However, you should realize that frames will be skipped to make sure the sound stays synchronized. Naturally, this only happens to users on slower-performing machines. It's just that often it's more important that every frame of your animation appears even if it means the sounds may drift out of synchronization. My point is that you should only use Stream when the synchronization is critical (and you don't mind dropping frames). Otherwise, use Event or Start.

Figure 10.6 The same animation and sound with frame- rates of 18fps (top) and 6fps (bottom). Notice that keyframes and tweening are not affected, but the sound needs to take more room when the Timeline is only advancing six frames per second (the audio can't expand or contract because that would sound funny).

Effect Settings

The Properties panel provides some pretty fancy effects you can apply to a selected sound. In the drop-down list next to Effect, you'll find effects such as Fade In and Fade Out as well as Fade from Left to Right and Fade from Right to Left. In order to understand and customize these settings further, you can either select Custom from the list or click the Edit... button on the Properties panel to access the Edit Envelope dialog box, as shown in Figure 10.7.

Figure 10.7 The Edit Envelope dialog box lets you select from pre-built panning effects or create your own.

  • Left Channel/Right Channel will display different wave forms if your original sound was stereo. Even if you only use mono sounds, you'll get the left and right channels so that you can still create panning effects. In the case of mono, the same sounds will come out of each speaker—you'll just be able to modify the volume of each.

  • Envelope lines indicate the volume level at any particular time in the sound. When the line is at the top, the sound plays at full 100% volume. (Some audio tools are different because they use the middle to indicate 100% and anything higher to indicate amplified or boosted sound, but this is not the case in Flash.) If the envelope line is getting higher as you move to the right, the volume will increase.

  • Envelope handles are like keyframes within the sound. If you want the envelope lines (indicating volume) to change direction, you'll need to insert a handle, which acts almost like a keyframe for sound. All you need to do is click anywhere on a line and a handle will be inserted. No matter which channel you click, a matching handle is placed in the other channel. A handle in one channel must match the moment in time (left to right) of the handle in the other channel. However, the volume (height) can vary between the two.

  • Time In lets you establish the starting point of a sound. You're effectively trimming the extra sound (or silence) at the beginning of the sound file. You're not telling the sound to start any later, but the sound you hear will begin wherever the Time In marker is placed.

  • Time Out lets you trim extra sound off the end of a sound file. Often you'll see a moment of silence at the end of a sound file, and even if you don't hear anything, it still adds to the file size! You can get rid of it by moving the Time Out marker to the left. You won't actually destroy the source sound in your Library, but when you export the movie, the unused portions of the sound won't be used (so your file stays small).

  • Stop/Play lets you preview all the settings you've made. This is important because although the waveform can let you "see" a sound, you ultimately want to judge the effect with your ears.

  • Zoom In/Out lets you zoom out so the entire sound fits in the current window or zoom in for a close up to control precisely how you place the Time In/Out markers or envelope handles.

  • Display units (Time or Frames) simply changes the units displayed (in the center portion) from time units (seconds) to frame units. Time is not as useful when you want to match your sound to a particular frame (where something visual occurs). If the display shows a peak in the music at 1 second, you have to use framerate to calculate exactly which frame that translates to. With the display set to Frames, Flash will do the calculations for you.

Panning is an effect that makes sound seem to move from left to right or right to left. It's simply a trick in which the volume for one channel (left or right) is increased while the volume for the other channel is decreased. When combined with a graphic moving in the same direction, this technique can be very effective. Imagine, for example, a car moving across the screen at the same time the audio pans in the same direction.

Despite all the details in the Edit Envelope dialog box, you really only have two basic ways to use it: You can either use a preset effect or make your own. Actually, you can start with a preset (such as Fade In) and then make modifications to it, essentially making a custom effect based on a preset. Use the effects in any way you think appropriate. Listen to the effect after each change by clicking the Play button. Nothing you do here will affect the master sound in your Library. You can actually use the same sound several times throughout your movie, with different effects in each instance.

One of the most important things to remember is that the Time In and Time Out markers can save file size. Only the sounds and portions of sounds actually used will be exported when you publish your movie. Unused sounds in the Library and portions trimmed from the beginning or end of a sound will not be exported. Trimming a few seconds off the end of a sound can mean many seconds (even minutes) saved in download time for your users. Also, changing the volume of a sound has no impact on file size, so setting the envelope lines to the lowest level makes no sense.

Loop Settings

Finally, note the Properties panel has a field where you specify the number of loops a particular sound should play. This simply makes the sound repeat the specified number of times without any pauses. This is great for sounds that loop well.

Some sounds loop better than others. Basically, a sound that loops well ends the same way it starts. There's an art to making sounds loop. Although importing a large song and using the Time In and Time Out markers to establish a nice looping sound is possible, it won't be easy. More likely, you'll have to find a sound already prepared by an audio engineer. A professionally prepared sound can loop so seamlessly that you can listen to it and not even notice it's looping; it will just sound like it's endless.

Also, if you have a sound that you want to loop "forever" (and you're satisfied with its loop quality), the standard and recommended practice in Flash is to just put a very large number into the Loop field. Although it seems strange, that's how you do it. If you type 99999999999, Flash changes this entry to 2147483647. I suppose a very patient viewer could outlast the total number of loops, but consider that a one-second sound repeated 2,147,483,647 times takes 68 years to finish!


By the way, creating loops and even songs built from many separate loops isn't all that difficult. Tools such as Sonic Foundry's Sound Forge and Acid Pro give you all the tools necessary to create and assemble loops. These are professional tools that go beyond the needs of average Flash users—but you'll probably be surprised how easy you can create music. Like Flash, you can try Sound Forge and Acid Pro free.

  • + Share This
  • 🔖 Save To Your Account