Using Sound


There are many uses for sound in Flash. Sound can include a voiceover to a presentation, sound effects for an animation, user interaction cues, jukebox lineups, and any kind of ambient soundtrack for your site. Although Flash doesn't provide any sound-editing tools, it does give you a wide variety of options for embedding and playing external sound files for any type of project you are working on.

Flash has two types of playback sound. The first is event sound, which must be completely downloaded into the user's system before it begins playing. These types of sounds continue playing until stopped, when they either run to the end of their cycle or receive a command from ActionScript. Event sounds are used for short sound effects or other sounds that play over and over. The second type is streaming sound. Streaming sounds are synchronized to the timeline and begin playing as soon as enough data is downloaded for a few frames to play. They are used whenever the sound needs to be synced to an animation or when you want it to end at a specific moment on the timeline.

Importing Sounds

By default, both Windows and Mac systems can import MP3 files into Flash. In addition to MP3, which is a compressed file format, Macs can import AIFF files and Windows can import WAV files into Flash. Additional audio file formats can be imported if QuickTime 4 or later is installed on your system. When you add multimedia to your Flash projects, always start with high-quality, uncompressed content whenever possible, which means 16-bit WAV or AIFF audio and .mov or .avi content for video. These files can then be compressed in Flash and encoded in the .flv format.

To import a sound file go to File, Import, Import to Library and select the file you want to import from your system files. Another way to import sound files into a Flash project is to drag them from a common library (Windows, Common Libraries, Sounds) to the library or onto the stage of your current Flash project.

Adding Sound to Your Timeline

To add sound to any timeline you must first import the sound file as described in the previous section. Then create a new layer in the timeline for the sound, make sure this layer is selected, and create or select a blank keyframe on the new layer where you want the sound to begin. In the Property inspector, choose the name of the sound from the Sound menu. Choose your settings and add frames to the layer as needed for correct playback. See Figure 15.12 for an illustration of how to add sound to the timeline.

Figure 15.12. Adding sound to the timeline.


Adding sound to a button symbol instance is an easy way to learn this process. To start from scratch, draw a simple shape on the stage. Next, select the drawing and convert it to a symbol (Modify, Convert to Symbol), choose Button as the type, and give it a name. Go into symbol edit mode by double-clicking the symbol and you should see the four frames of a button timeline, as shown in Figure 15.13.

Figure 15.13. The four frames of a button symbol's timeline.


Begin by adding a new layer called sound. If you want to have the sound play when the user clicks on the button symbol, select the frame labeled "Down" and insert a blank keyframe (F7) on the new sound layer. With the blank keyframe selected, drag one of the sounds from the Window, Common Libraries, Sounds library to the stage. That's it! You've added sound to your button. Use Test Movie, (Cmd-Return) [Ctrl+Enter] to export the SWF, and the sound plays when you click on the button.

This is the same process you would use to add sound to any frame in the movie, changing the sync setting to fit the particular sound. The sound file plays at the same rate as any animation on the stage. To create an animated mini-music video, you could have your animation elements on their own layers of the timeline, and the music sound file on a separate layer.

Changing Imported Sound Properties

Although you can't really edit sounds within Flash, you can modify properties of those sounds and apply a number of effects to them. For example, you can change the envelope of the sound and add effects such as fade out. The envelope is basically the wrapping that Flash puts around the sound file, which tells Flash how to play back the file.

To edit a sound's properties in Flash, first select the frame in which the sound starts and then view the options in the Property inspector, as shown in Figure 15.14.

Figure 15.14. Property inspector for a sound.


In the Property inspector you can apply effects to your sound by selecting options from the Effect drop-down. These include Fade Out (the sound fades from its current volume to silence) and Fade Left to Right (the sound fades from the left speaker to the right speaker). To edit an existing effect or create a custom effect, click the Edit button next to the Effect drop-down menu. This brings up the Sound Edit Envelope panel (see Figure 15.15), where you can edit how the effects are applied to your sound. The upper view shows the left channel and the lower view shows the right channel. The ruler in the middle is the timeline for the sound, which enables you to trim the sound with the time-in and time-out handles on the left and right sides.

Figure 15.15. The Sound Edit Envelope panel enables you to edit how effects are applied to your sound track.


To change the effect, you can select one of the preset options (such as fade in or fade out) in the drop-down menu. To create your own custom effect, click anywhere on the upper or lower view to add a new point on the envelope rubber band. This point can be dragged up or down to raise the volume or lower it. Remember that just as with video, trimming a sound file doesn't decrease the file size. If you need to edit the sound for length, you should use a sound-editing program and then update the sound file in the project's library.

You can also choose from the following Sync properties with the Property inspector:

  • Event sync sounds need to download before playing and play to the end of the sound, creating new iterations of the sound each time the starting keyframe is reached on the timeline.

  • Start sync sounds are the same as Event sounds, but do not start a new iteration of the sound if the playback head returns to the keyframe until the previous sound has ended. This is useful for looping sounds on your timeline.

  • Stop sync sounds enable you to stop the sound at the chosen keyframe to which the sync is added.

  • Stream sync sounds are tied to the timeline on which they occur and play as fast as they are downloaded. You can also set how many times the sound repeats, either by setting a specific number of repetitions or directing the sound to loop continually.

Now that you have an understanding of how to bring sound files into Flash, you are ready for some more advanced topics such as compression and loading external MP3 files.

SWF Sound Export Compression

MP3 files that are imported and embedded use the settings with which they were imported with, whereas AIFF and WAV files have compression performed on them as the SWF file is created.

Different types of sounds can be compressed with different methods that are uniquely suited to provide high sound quality and compression for that type of sound. It's a good idea to find the balance between compression and quality, because although you want to minimize the file size as much as possible, there is little point in having an overcompressed file that sounds terrible. The following list shows which compression setting should be used with different sound types:

  • ADPCM compression Short event sounds such as button clicks

  • MP3 compression Longer stream sounds such as music sound tracks

  • Speech compression Compression that is adapted to speech

  • Raw No compression is applied

There are two different scopes for setting sound compression: globally for the entire document and all of the sound files in it, or individually for each sound file used in the document.

The global setting is applied to all sounds, both event and streaming. You can find this by going to File, Publish Settings and choosing the Flash tab. Near the bottom of the dialog box, the compression settings for Streaming and Event audio are displayed. To change them, click the Set button. The default setting for the global compression settings is the MP3 option.

Individual settings for a sound file override the global settings configured in the Publish settings. If you've embedded a number of AIFF and WAV files into your document, this is the best route to getting the tightest compression with the highest sound quality. To create individual settings, open the Library and double-click the individual sound file icon. In the Sound Properties dialog box, you can select and test the compression settings for that sound. These include Sample rate for Speech, and Bit rate and Quality for MP3.

Loading External MP3 Files

If you're working with large sound files, especially if they are not tightly tied to animation on the timeline, you should consider loading external MP3 files. The benefit to this is that it decreases the file size of the published .swf file, and allows flexibility similar to that of using external video files. You can more easily change and stream the content, and allow the user to initiate download of sound files without having to wait for the application and all its assets to download.

You can control the loading and playback of external MP3 files with ActionScript. As shown in the following code, you must first create a new Sound object. Then you can load the external .mp3 file into your Sound object instance. After it is loaded, you can play the sound:

mySound = new Sound(); mySound.loadSound(myfile.mp3); mySound.start();


Use the following code to stop the sound at any point:

mySound.stop();


You can also add some simple buttons to let the user stop and start the .mp3 file after it is loaded. If you name your buttons soundPlay_mc and soundStop_mc, you could use this code:

soundStart_mc.onRelease = function(){     mySound.start(); } soundStop_mc.onRelease = function(){     mySound.stop(); }


The sound object gives you control over how you load and use external sound files in your applications. Working with external MP3 files and ActionScript, you can create some sophisticated applications, including a Flash jukebox.



Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

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