What is Software? | What is Education? | What is Technology? | What is Research? | What is Wi-Fi? | What is Communication? | What is Customer Service?

Free SEO Tutorials & Help

Tutorials:   Adobe Flash   Adobe Photoshop   CorelDRAW   SEO  

Site Map

Website Development | Cable & Broadband Magazine | Solutions for Higher Education | Auction Anything Online

Adobe Flash Help & Tutorials

 Back to Topics

 

How to Work with Sound in Flash

Importing sounds

Adding sounds to a document

Adding sounds to buttons

Using sounds with Sound objects

About accessing ID3 properties in MP3 files with Flash Player

Using the sound-editing controls

Controlling sound playback using behaviors

Starting and stopping sounds at keyframes

About the onSoundComplete event

Using the ADPCM compression option

Using the MP3 compression option

Using the Raw compression option

Using the Speech compression option

Guidelines for exporting sound in Flash documents

About using sounds in Flash Lite

 

Importing sounds

TOP

You place sound files into Flash by importing them into the library for the current document.

NOTE : When placing a sound in the Timeline, you place it on a separate layer.

  • You can import the following sound file formats into Flash:

  • WAV (Windows only)

  • AIFF (Macintosh only)

  • MP3 (Windows or Macintosh)

If you have QuickTime 4 or later installed on your system, you can import these additional sound file formats:

  • AIFF (Windows or Macintosh)

  • Sound Designer II (Macintosh only)

  • Sound Only QuickTime Movies (Windows or Macintosh)

  • Sun AU (Windows or Macintosh)

  • System 7 Sounds (Macintosh only)

  • WAV (Windows or Macintosh)

Flash stores sounds in the library along with bitmaps and symbols. As with graphic symbols, you need only one copy of a sound file to use that sound multiple ways in your document.
If you want to share sounds among Flash documents, you can include the sounds in shared libraries. To use a sound in a shared library, you assign the sound file an identifier string in the Linkage Properties dialog box. The identifier can also be used to access the sound as an object in ActionScript.

Sounds can use considerable amounts of disk space and RAM. However, MP3 sound data is compressed and smaller than WAV or AIFF sound data. Generally, when using WAV or AIFF files, it's best to use 16-bit 22 kHz mono sounds (stereo uses twice as much data as mono), but Flash can import either 8- or 16-bit sounds at sample rates of 11, 22, or 44 kHz. Flash can convert sounds to lower sample rates on export.

NOTE : Sounds recorded in formats that are not multiples of 11 kHz (such as 8, 32, or 96 kHz) are resampled when imported into Flash.

If you want to add effects to sounds in Flash, it's best to import 16-bit sounds. If you have limited RAM, keep your sound clips short or work with 8-bit sounds instead of 16-bit sounds.

To import a sound:

  1. Select File > Import > Import to Library.

  2. In the Import dialog box, locate and open the desired sound file.

NOTE : You can also drag a sound from a common library into the library for the current document.

 

Adding sounds to a document

TOP

To add a sound to a document from the library, you assign the sound to a layer and set options in the Sound controls in the Property inspector. It is recommended that you place each sound on a separate layer.

You can load a sound into a SWF file during runtime, using the loadSound method of the Sound object.

To test sounds that you add to a document, you can use the same methods you use to preview frames or test SWF files: Drag the playhead over the frames containing the sound or use commands in the Controller or the Control menu.

To add a sound to a document:

  1. Import the sound into the library if it has not already been imported. For more information, see Importing sounds.

  2. Select Insert > Timeline > Layer to create a layer for the sound.

  3. With the new sound layer selected, drag the sound from the Library panel onto the Stage. The sound is added to the current layer.

    You can place multiple sounds on one layer or on layers containing other objects. However, it is recommended that each sound be placed on a separate layer. Each layer acts as a separate sound channel. The sounds on all layers are combined when you play the SWF file.

  4. In the Timeline, select the first frame that contains the sound file.

  5. Select Window > Properties and click the arrow in the lower right corner to expand the Property inspector.

  6. In the Property inspector, select the sound file from the Sound pop-up menu.

  7. Select an effect option from the Effects pop-up menu:

    None applies no effects to the sound file. Select this option to remove previously applied effects.

    Left Channel/Right Channel plays sound in the left or right channel only.

    Fade Left to Right/Fade Right to Left shifts the sound from one channel to the other.

    Fade In gradually increases the volume of a sound over its duration.

    Fade Out gradually decreases the volume of a sound over its duration.

    Custom lets you create custom in and out points of sound using the Edit Envelope. For more information, see Using the sound-editing controls.

  8. Select a synchronization option from the Sync pop-up menu:

    NOTE : If you are placing the sound on a frame other than Frame 1 in the main Timeline, select the Stop option.

    Event synchronizes the sound to the occurrence of an event. An event sound plays when its starting keyframe first appears and plays in its entirety, independently of the Timeline, even if the SWF file stops playing. Event sounds are mixed when you play your published SWF file.

    An example of an event sound is a sound that plays when a user clicks a button. If an event sound is playing and the sound is instantiated again (for example, by the user clicking the button again), the first instance of the sound continues to play and another instance begins to play simultaneously.

    Start is the same as Event, except that if the sound is already playing, no new instance of the sound plays.

    Stop silences the specified sound.

    Stream synchronizes the sound for playing on a website. Flash forces animation to keep pace with stream sounds. If Flash can't draw animation frames quickly enough, it skips frames. Unlike event sounds, stream sounds stop if the SWF file stops playing. Also, a stream sound can never play longer than the length of the frames it occupies. Stream sounds are mixed when you publish your SWF file.

    An example of a stream sound is the voice of a character in an animation that plays in multiple frames.

    NOTE : If you use an MP3 sound as a stream sound, you must recompress the sound for export. You can export the sound as an MP3 file, with the same compression settings that it had on import. For more information, see Compressing sounds for export.

  9. Enter a value for Repeat to specify the number of times the sound should loop, or select Loop to repeat the sound continuously.

    For continuous play, enter a number large enough to play the sound for an extended duration. For example, to loop a 15-second sound for 15 minutes, enter 60. Looping stream sounds is not recommended. If a stream sound is set to loop, frames are added to the file and the file size is increased by the number of times the sound is looped.

 

Adding sounds to buttons

TOP

You can associate sounds with the different states of a button symbol. Because the sounds are stored with the symbol, they work for all instances of the symbol.

To add sound to a button:

  1. Select the button in the Library panel.

  2. Select Edit from the options menu in the upper right corner of the panel.

  3. In the button's Timeline, add a layer for sound.

  4. In the sound layer, create a regular or blank keyframe to correspond with the button state to which you want to add a sound.

    For example, to add a sound that plays when you click the button, create a keyframe in the frame labeled Down.

  5. Click the keyframe you created.

  6. Select Window > Properties.

  7. In the Property inspector, select a sound file from the Sound pop-up menu.

  8. Select Event from the Synchronization pop-up menu.

    To associate a different sound with each of the button's keyframes, create a blank keyframe and add another sound file for each keyframe. You can also use the same sound file and apply a different sound effect for each button keyframe. For more information, see Using the sound-editing controls.

 

Using sounds with Sound objects

TOP

You can use the Sound object in ActionScript to add sounds to a document and to control sound objects in a document. Controlling sounds includes adjusting the volume or the right and left balance while a sound plays.

To use a sound in a Sound action, you assign an identifier string to the sound in the Linkage Properties dialog box.

To assign an identifier string to a sound:

  1. Select the sound in the Library panel.

  2. Do one of the following:

    • Select Linkage from the options menu in the upper right corner of the panel.

    • Right-click (Windows) or Control-click (Macintosh) the sound name in the Library panel, and select Linkage from the context menu.

  3. Under Linkage in the Linkage Properties dialog box, select Export for ActionScript.

  4. Enter an identifier string in the text box, and click OK

 

About accessing ID3 properties in MP3 files with Flash Player

TOP

Macromedia Flash Player 7 and later supports ID3 v2.4 and v2.4 tags. With this version, when you load an MP3 sound using the attachSound() or loadSound() method, the ID3 tag properties are available at the beginning of the sound data stream. The onID3 event executes when the ID3 data is initialized.

Flash Player 6 (6.0.40.0) and later supports MP3 files with ID3 v1.0 and v1.1 tags. With ID3 v1.0 and v1.1 tags, the properties are available at the end of the data stream. If a sound does not contain an ID3v1 tag, the ID3 properties are undefined. Users must have Flash Player 6 (6.0.40.0) or later for the ID3 properties to function.

 

Using the sound-editing controls

TOP

To define the starting point of a sound or to control the volume of the sound as it plays, you use the sound-editing controls in the Property inspector.

Flash can change the point at which a sound starts and stops playing. This is useful for making sound files smaller by removing unused sections.

To edit a sound file:

  1. Add a sound to a frame (for more information, see Adding sounds to a document), or select a frame that already contains a sound.

  2. Select Window > Properties.

  3. Click the Edit button on the right side of the Property inspector.

  4. Do any of the following:

    • To change the start and end points of a sound, drag the Time In and Time Out controls in the Edit Envelope.

    • To change the sound envelope, drag the envelope handles to change levels at different points in the sound. Envelope lines show the volume of the sound as it plays. To create additional envelope handles (up to eight total), click the envelope lines. To remove an envelope handle, drag it out of the window.

    • To display more or less of the sound in the window, click the Zoom In or Out buttons.

    • To switch the time units between seconds and frames, click the Seconds and Frames buttons.

  5. To hear the edited sound, click the Play button.

 

Controlling sound playback using behaviors

TOP

You can control sound playback using sound behaviors. Behaviors are prewritten ActionScript scripts that you apply to an object, such as a button, to control a target object, such as a sound. Behaviors enable you to add the power, control, and flexibility of ActionScript coding to your document without having to create the ActionScript code yourself.

NOTE : Flash Lite 1.0 and Flash Lite 1.1 do not support behaviors.

You can use the Load Sound from Library or Load Streaming MP3 File behaviors to add a sound to your document. Adding a sound using these behaviors creates an instance of the sound. The instance name is then used to control the sound.

The Play Sound, Stop Sound, and Stop All Sounds behaviors let you control sound playback. To use these behaviors, you must first load a sound with one of the Load behaviors. To play or stop a sound with a behavior, you use the Behaviors panel to apply the behavior to a triggering object, such as a button. You specify the event that triggers the behavior (such as clicking the button), select a target object (the sound to be affected by the behavior), and select settings for the behavior parameters to specify how the behavior executes.

To load a sound to a file using a behavior:

  1. Select the object, such as a button, that you want to use to trigger the behavior.

  2. In the Behaviors panel (Window > Behaviors), click the Add (+) button and select Sound > Load Sound from Library or Sound > Load Streaming MP3 File.

  3. In the Load Sound dialog box, enter the linkage identifier for a sound from the Library, or the sound location for a streaming MP3 file. Next, enter a name for this instance of the sound, and click OK.

  4. In the Behaviors panel under event, click On Release (the default event), and select a mouse event from the menu. If you want to use the OnRelease event, do not change the option.

To play a sound using a behavior:

  1. Select the object, such as a button, that you want to use to trigger the Play Sound behavior.

  2. In the Behaviors panel (Window > Behaviors), click the Add (+) button.

  3. Select Sound > Play Sound.

  4. In the Play Sound dialog box, enter the instance name of the sound you want to play, and click OK.

  5. In the Behaviors panel under Event, click On Release (the default event) and select a mouse event from the menu. If you want to use the OnRelease event, leave the option unchanged.

To stop a sound using a behavior:

  1. Select the object, such as a button, that you want to use to trigger the Play Sound behavior.

  2. In the Behaviors panel (Window > Behaviors), click the Add (+) button.

  3. Select Sound > Stop Sound.

  4. In the Stop Sound dialog box, enter the linkage identifier and the instance name of the sound you want to stop, and click OK.

  5. In the Behaviors panel under Event, click On Release (the default event) and select a mouse event from the menu. If you want to use the OnRelease event, leave the option unchanged.

To stop all sounds using a behavior:

  1. Select the object, such as a button, that you want to use to trigger the Stop All Sounds behavior.

  2. In the Behaviors panel (Window > Behaviors), click the Add (+) button.

  3. Select Sound > Stop All Sounds.

  4. In the Stop All Sounds dialog box, click OK to verify that you want to stop all sounds.

  5. In the Behaviors panel, under Event Click On Release (the default event) and select a mouse event from the menu. If you want to use the OnRelease event, leave the option unchanged.

 

Starting and stopping sounds at keyframes

TOP

The most common sound-related task in Flash is starting and stopping sounds at keyframes to synchronize with animation.

To stop and start a sound at a keyframe:

  1. Add a sound to a document. For more information, see Adding sounds to a document.

    To synchronize this sound with an event in the scene, select a beginning keyframe that corresponds to the keyframe of the event in the scene. You can select any of the synchronization options.

  2. Create a keyframe in the sound layer's Timeline at the frame where you want the sound to end.

    A representation of the sound file appears in the Timeline.

  3. Select Window > Properties and click the arrow in the lower right corner to expand the Property inspector.

  4. In the Property inspector, select the same sound from the Sound pop-up menu.

  5. Select Stop from the Synchronization pop-up menu.

    When you play the SWF file, the sound stops playing when it reaches the ending keyframe.

  6. To play back the sound, simply move the playhead.

 

About the onSoundComplete event

TOP

The onSoundComplete event of the ActionScript Sound object lets you trigger an event in a Flash application based on completing an attached sound file. The Sound object is a built-in object that lets you control sounds in a Flash application.  The onSoundComplete event of a Sound object is invoked automatically when the attached sound file finishes playing. If the sound is looped a specified number of times, the event is triggered when the sound finishes looping.

The Sound object has two properties that you can use with the onSoundComplete event. The duration property is a read-only property representing the duration, in milliseconds, of the sound sample attached to the sound object. The position property is a read-only property representing the number of milliseconds the sound has been playing in each loop.

The onSoundComplete event lets you manipulate sounds in a variety of powerful ways, such as the following:

  • Creating a dynamic playlist or sequencer

  • Creating a multimedia presentation that checks for narration completion before advancing to the next frame or scene

  • Building a game that synchronizes sounds to particular events or scenes and transitions smoothly between different sounds

  • Timing an image change to a sound--for example, changing an image when a sound is halfway through at playback time

 

Using the ADPCM compression option

TOP

The ADPCM compression option sets compression for 8- or 16-bit sound data. Use the ADPCM setting when you export short event sounds such as button clicks.

To use ADPCM compression:

  1. In the Sound Properties dialog box, select ADPCM from the Compression menu.

  2. For Preprocessing, select Convert Stereo to Mono to convert mixed stereo sounds to monaural (mono). (Mono sounds are unaffected by this option.)

  3. For Sample Rate, select an option to control sound fidelity and file size. Lower rates decrease file size but can also degrade sound quality. Rate options are described in the following list:

5 kHz is barely acceptable for speech.

11 kHz is the lowest recommended quality for a short segment of music and is one-quarter of the standard CD rate.

22 kHz is a popular choice for web playback and is half the standard CD rate.

44 kHz is the standard CD audio rate.

NOTE : Flash cannot increase the kHz rate of an imported sound above the rate at which it was imported.

Using the MP3 compression option

TOP

The MP3 compression option lets you export sounds with MP3 compression. Use MP3 when you are exporting longer stream sounds such as music sound tracks.

If you are exporting a file that was imported in MP3 format, you can export the file using the same settings the file had when it was imported.

To export an imported MP3 file with the same settings the file had when it was imported:

  1. In the Sound Properties dialog box, select MP3 from the Compression menu.

  2. Select Use Imported MP3 Quality (the default setting). Deselect this option to select other MP3 compression settings, as defined in the following procedure.

To use MP3 compression:

  1. In the Sound Properties dialog box, select MP3 from the Compression menu.

  2. Deselect Use Imported MP3 Quality (the default setting).

  3. For Bit Rate, select an option to determine the bits per second in the exported sound file. Flash supports 8 through 160 Kbps CBR (constant bit rate). When you are exporting music, set the bit rate to 16 Kbps or higher for the best results.

  4. For Preprocessing, select Convert Stereo to Mono to convert mixed stereo sounds to monaural. (Mono sounds are unaffected by this option.)

    NOTE : The Preprocessing option is available only if you select a bit rate of 20 Kbps or higher.

  5. For Quality, select one of the following options to determine the compression speed and sound quality:

    Fast yields faster compression but lower sound quality.

    Medium yields somewhat slower compression but higher sound quality.

    Best yields the slowest compression and the highest sound quality.

 

Using the Raw compression option

TOP

The Raw compression option exports sounds with no sound compression.

To use raw compression:

  1. In the Sound Properties dialog box, select Raw from the Compression menu.

  2. For Preprocessing, select Convert Stereo to Mono to convert mixed stereo sounds to monaural. (Mono sounds are unaffected by this option.)

    For Sample Rate, select an option to control sound fidelity and file size. Lower rates decrease file size but can also degrade sound quality. Rate options are described in the following list:

    5 kHz is barely acceptable for speech.

    11 kHz is the lowest recommended quality for a short segment of music and is one-quarter of the standard CD rate.

    22 kHz is a popular choice for web playback and is half the standard CD rate.

    44 kHz is the standard CD audio rate.

    NOTE : Flash cannot increase the kHz rate of an imported sound above the rate at which it was imported.

 

Using the Speech compression option

TOP

The Speech compression option exports sounds using a compression that is adapted to speech.

NOTE : Flash Lite 1.0 and Flash Lite 1.1 do not support the Speech compression option. For content targeting those player versions, use MP3, ADPCM, or Raw compression.

To use speech compression:

  1. In the Sound Properties dialog box, select Speech from the Compression menu.

  2. For Sample Rate, select an option to control sound fidelity and file size. A lower rate decreases file size but can also degrade sound quality. Select from the following options:

    5 kHz is acceptable for speech.

    11 kHz is recommended for speech.

    22 kHz is acceptable for most types of music on the web.

    44 kHz is the standard CD audio rate. However, because compression is applied, the sound is not CD quality in the SWF file.

 

Guidelines for exporting sound in Flash documents

TOP

Besides sampling rate and compression, there are several ways to use sound efficiently in a document and keep file size small:

  • Set the in and out points to prevent silent areas from being stored in the Flash file and to reduce the size of the sound.

  • Get more out of the same sounds by applying different effects for sounds (such as volume envelopes, looping, and in/out points) at different keyframes. You can get a number of sound effects using only one sound file.

  • Loop short sounds for background music.

  • Do not set streaming sound to loop.

  • When exporting audio in embedded video clips, remember that the audio is exported using the global streaming settings selected in the Publish Settings dialog box.

  • Use stream synchronization to keep the animation synchronized to your sound track when you preview your animation in the editor. If your computer is not fast enough to draw the animation frames so that they keep up with your sound track, Flash skips frames.

  • When exporting QuickTime movies, use as many sounds and channels as you want without worrying about file size. The sounds are combined into a single sound track when you export as a QuickTime file. The number of sounds you use has no effect on the final file size.

 

About using sounds in Flash Lite

TOP


Flash Lite supports two types of sound: standard Flash sounds, like those used in Flash desktop applications, and device sounds. Flash Lite 1.0 supports device sounds only; Flash Lite 1.1 supports both standard sounds and device sounds.

Device sounds are stored in the published SWF file in their native audio format (such as MIDI or MFi); during playback, Flash Lite passes the sound data to the device, which decodes and plays the sound. Because you can't import most device audio formats into Flash, you instead import a proxy sound in a supported format (such as MP3 or AIFF) that is replaced with an external device sound that you specify.

You can use device sounds only as event sounds--you can't synchronize device sounds with the Timeline. Unlike device sounds, you can synchronize standard sounds to the Timeline.

Flash Lite 1.0 and Flash Lite 1.1 do not support the following features available in the desktop version of Flash Player:

  • The ActionScript Sound object

  • Loading of external MP3 files

  • The Speech audio compression option (see Compressing sounds for export)

 

Copyright ADOBE - All Rights Reserved Worldwide

 

 

More Topics:

Working with Flash Documents

How to work in Flash WorkSpace

Working with Projects in Flash

Process to Build your First Application in Flash

Using Symbols, Instances and Library Assets in Flash

How to Build Video Player in Flash

How to Work with Color, Strokes and Fills in Flash

How to Create Document in Flash

What is Vector and Bitmap Graphics in Flash

How to Create a Banner in Flash, Part 1

How to Work with Text in Flash

How to Create a Banner in Flash, Part 2

How to Use Imported Artwork in Flash

How to Create a Banner in Flash, Part 3

How to Work with Graphic Objects in Flash

How to Work with Layers in Flash

How to Use Filters and Blends

Working with Graphics in Flash

What is Accessibility Features in Flash

How to Create Motion (Shape Tween & Motion Tween) in Flash

How to Create an Application in Flash

What is Masking in Flash

How to Work with Video in Flash

How to Use Layout Tools in Flash

What are Behaviors in Flash

How to Work with Sound in Flash

How to Create Symbols and Instances in Flash

What is ActionScript in Flash

How to Write ActionScript With Script Assist in Flash

How to Add Button Animation and Navigation in Flash

What is Data Integration in Flash

How to Work with Screens

How to Create a Presentation with Screens

What is Extending Flash

How to Create Multilanguage Text in Flash

How to Create Graphics: Draw in Flash

What is Flash Lite

Ways of Data Integration

How to Create Graphics: Create a Timeline Animation in Flash

Getting Started with Flash Lite in Flash

How to Publish Flash Documents

How to Create Graphics: Making Animations with Easing

Learning Flash Lite 1.X ActionScript in Flash

How to Export Flash Content and Images from Flash

How to Create Graphics: Applying Gradients in Flash

Process of Writing and Editing ActionScript 2.0 in Flash

How to Create Accessible Content in Flash

How to Create Graphics: Apply Graphic Filters and Blends

What is Data and Data Types in Flash

Process of Printing from SWF Files in Flash

Using ActionScript: How to Use Script Assist mode in Flash

Learn Syntax and Language Fundamentals in Flash

How to Create E-learning Content in Flash

Using ActionScript: How to Write Scripts in Flash

Working with Functions and Methods in Flash

Process of Using Templates in Flash

Using ActionScript: Process of Adding Interactivity in Flash

What are Classes in Flash

Control Tag Summary of XML to UI in Flash

Using ActionScript: How to Create a Form with Conditional Logic and Send Data in Flash

What is Inheritance in Flash

What is Data Integration: Overview

Using ActionScript: How to Work with Objects and Classes in Flash

Overview on Interfaces in Flash

What is Data Integration: Using XML for a Timesheet

How to Work with Text and Strings in Flash

How to use Handling Events in Flash

What is Data Integration: Using XUpdate to Update the Timesheet

Learning Animation, Filters and Drawings in Flash

How to Work with Movie Clips in Flash

How to Create Interaction with ActionScript in Flash

How to Work with Images, Sound, and Video in Flash

How to Work with External Data in Flash

What is Security in Flash

How to Debug Applications in Flash

List of Error Messages in Flash

Using Object-Oriented Programming with ActionScript 1.0 in Flash

How to Write Scripts for Earlier Versions of Flash Player in Flash

List of all Keyboard Keys and Key Code Values for using in Flash

Terminology

Introduction to Components in Flash

What are Components in Flash

How to Create an Application with Components

How to Work with Components in Flash

How to Handle Component Events in Flash

How to Customize Components in Flash

How to Create Components in Flash

What is Collection Properties in Flash