|< Day Day Up >|
Now that you've imported sounds into a movie, you 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. (An exception is adding sounds dynamically by using the Sound object in the ActionScript language for which I'll provide the starter code after this hour's summary.) 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 rather more complex, and we'll cover it in depth in Hour 14, "Making Buttons for the User to Click."
Now that you understand sounds go in keyframes, you 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 (a picture of a sound) for the sounds being used (as shown in Figure 10.3).
Figure 10.3. The waveform is displayed in the Timeline. This is helpful when you're trying to synchronize images with specific parts of sound.
However, using the Properties panel is the best way to see which sounds have been added to which keyframes. 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, you see that 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.
When you have the Properties panel reflecting sound for the intended keyframe, you can decide exactly how the sound should play. The most fundamental choice you need to make is the Sync setting. This controls exactly how a particular instance of the sound will play or, more specifically, the priority of the sound compared to the visual elements in the animation. Before you try out the Sync settings, see the following list and Figure 10.5 for an explanation of each:
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 doesn't need to be synchronized. Therefore, you should use Event for it. Start is a perfectly good alternative to Event because it's the same but prevents the same sound from layering on itself. 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 will become discordant. If you use the Start Sync setting, only one instance of the sound will 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. Conversely, say you want to hear a "smack" sound effect every time a ball bounces on the ground. If you choose Event, you'll hear a smack for each bounce, even if the ball bounces a second time before the first sound finishes. In any event, Start and Event are good for the majority of sounds you'll play.
Rollover is when the user places his or her cursor over a button, so a rollover sound is a sound that plays when the user rolls over a button. You'll learn about rollover effects for buttons in Hour 14.
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 stops only one sound per keyframe. When you learn about behaviors (in Hour 15, "Using ActionScript and Behaviors to Create Nonlinear Movies"), you'll learn that you can insert the Stop All Sounds behavior to stop all sounds at once. Depending on the situation, this might be appropriate. If you're giving the user the ability to get several sounds going at once, you'll want to learn about 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 setting to Event or Start. In the last frame of the tween, you can put the same sound effect but with the Stop Sync setting. 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 in which you want a character's lips to synchronize with its voice. When trying to synchronize sounds with images, you can use the scrub technique, and if you use Stream sounds, you can 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 frame rate. For example, a 3-second sound will take 36 frames at 12 fps. If you do some work and then change the frame rate to 24 fps, the same 3-second sound spans 72 frames! Flash automatically spreads the Stream sound out so that it takes 3 seconds when you change the frame rate, but Flash doesn't change your graphics, which now play in 1.5 seconds. See Figure 10.6 for a before-and-after example of changing the frame rate after an animation is built.
Figure 10.6. Here, the same animation and sound are shown with frame rates of 18 fps (top) and 6 fps (bottom). Notice that keyframes and tweening are not affected, but the sound uses less of the timeline when the timeline is only advancing at 6 fps. The short silence at the start of this sound means users won't hear anything until a few frames of the animation have played.
In spite of this issue, you should stick with a frame rate (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 on slower-performing machines, frames will be skipped to make sure a stream sound stays synchronized. It's often 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 use Stream only when the synchronization is critical (and you don't mind dropping frames). Otherwise, use Event or Start.
The Properties panel provides some pretty fancy effects you can apply to the volume of a selected sound. In the drop-down list next to Effect are 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, which is shown in Figure 10.7.
Figure 10.7. You can position the Sounds Common Library next to the Library for the keyframing sample file in order to transfer sounds.
Here are additional details for the Effect settings:
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 a 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 a 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.
The Properties panel has an option to either let you specify how many times a sound repeats or have the sound loop forever.
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 isn't 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.
You'll get to explore looping sounds as well as other effects in the next task.
Try It Yourself: Add Sounds and Sound Effects to an Animation
In this task you'll add sounds to a sample movie. Follow these steps:
|< Day Day Up >|