Using Sounds

 < 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.


Sync Settings

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:

  • Event Should be your default 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 the sound is done. Event sounds might not coincide with visual elements the same way on everyone's machine. Sounds don't play more slowly or quickly (that would make them sound funny), but a machine with slower graphics performance might take longer to display visual elements. Suppose you have a 1-second sound set to Event and your frame rate is 12 fps. You would expect that during the sound, 12 frames would be displayed, but a slow machine might display only 6 fps during that 1 second. In either case, the sound will finish 1 second later, as you would expect, but exactly how many frames will have been displayed can vary.

  • Start This setting 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." Start, on the other hand, plays a sound if it's not already playing.

  • Stop This setting is kind of weird it's for when you want a specified sound to stop playing. For example, say you import a sound called "background music" and make it start playing in the first keyframe of one layer. Then you import another sound, "narration," and make it start playing in the first keyframe of another layer. Then, in frame 10, you place another keyframe with the same sound (background music) set to Stop, just that sound will stop. Both sounds start at the beginning, but on frame 10 the background music stops and the narration continues to play. This is a bit strange because normally you use the Properties panel to specify the sound you want to play where here you specify the sound you want not to play. Think of Stop as "stop this sound if it's playing."

  • Stream This setting 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, this setting forces Flash to skip frames to keep up. Stream sounds start playing when the keyframe is reached and continue to play as long as there is space in the Timeline. In other words, if your sound is 3 seconds long and you're playing at 12 fps, the Timeline has to be at least 36 frames; otherwise, part of the sound will never be reached. (You can compare the Stream setting to a Graphic Symbol's behavior.) The benefit of the Stream setting is that the synchronization will always be the same. If in this case 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 that there are enough frames in the Timeline to accommodate the length of the sound. Finally, you preview Stream sounds 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 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.

Effect Settings

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:

  • Left Channel/Right Channel This option displays different wave forms if your original sound was stereo. Even if you use only mono sounds, you'll still 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 These 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 These are like keyframes within sound. If you want the envelope lines (indicating volume) to change direction, you need to insert a handle. 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 marker This marker 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 marker This marker lets you trim extra sound off the end of a sound file. Often you'll have 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 This option 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 of a sound with your ears.

  • Zoom In/Out This option 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) This option simply changes the units displayed (in the center portion) from time units (seconds) to frame units. Time is not as useful as Frames when you want to match 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 frame rate to calculate exactly which frame that translates to. With the display set to Frames, Flash does 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 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.

Loop Settings

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:

1.

Download the file keyframing.fla from my website (www.phillipkerman.com/teachyourself/sourcefiles). In Flash, open this file and then press Enter to watch the animation.

2.

Open the Library for the keyframing.fla file by selecting Window, Library (or pressing Ctrl+L).

3.

Now these sounds will be available to your file, but you need to put them into keyframes. First you need to make a new layer just for the sounds by selecting Insert, Timeline, Layer. (Don't worry if Flash puts the new layer under all others it doesn't really matter where it appears.) Name this layer Background Music. (You'll learn more about layers next hour.)

4.

Select the first frame of the Background Music layer and look at the Properties panel. From the Sound drop-down list, select Visor Hum Loop. To make this sound loop continuously, change the drop-down list from Repeat to Loop (see Figure 10.8).

Figure 10.8. Flash can loop a sound indefinitely with the Loop setting.


5.

Select Control, Test Movie. The sound loops nicely, and it adds a bit of drama to the movie. In the following steps, add some incidental sound effects.

6.

Select Insert, Timeline, Layer and name the layer Sound Effects. You're going to insert a sound effect right when the "8" is rotated to the left, which happens at frame 14. In Frame 14 of Sound Effects, select Insert, Timeline, Keyframe (or press F6).

7.

Select the keyframe you just inserted and from the Properties panel select Smack from the Sound drop-down list. Just leave the default settings (Event Sync and Repeat 1) because you don't want this sound to loop.

8.

Select Control, Test Movie. The Smack effect is good, but the hum keeps humming throughout the whole movie.

9.

To stop the hum, select Frame 30 of the Background Music layer and select Insert, Keyframe (or press F6). Make sure you're selecting just this keyframe, and then use the Properties panel to insert the Visor Hum Loop again, but this time select the Stop Sync setting to cause any instances of this sound to stop. (You can use Test Movie again to see and hear the results.)

10.

Finally, add a sound effect for when the pink sparkle animates. At Frame 30 of the Sound Effects layer, select Insert, Keyframe (or press F6), select just this keyframe, and then insert the Beam Scan sound. Use Test Movie, and it should be measurably better than the silent version. (By the way, these sounds only add about 3KB to the total file size!) One thing you can try is to remove the excess silence at the start of the Beam Scan sound. Just select Frame 30 in the Sound Effects layer and press Edit on the Properties panel. Then you can cut sound off the beginning by dragging the Time In marker in the Edit Envelope dialog box (refer to Figure 10.8).

     < Day Day Up > 


    Sams Teach Yourself Macromedia Flash 8 in 24 Hours
    Sams Teach Yourself Macromedia Flash 8 in 24 Hours
    ISBN: 0672327546
    EAN: 2147483647
    Year: 2006
    Pages: 235

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net