Flash
  Home arrow Flash arrow Page 4 - Adding Video and Sound
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Adding Video and Sound
By: Bill Sanders
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 31
    2004-07-12

    Table of Contents:
  • Adding Video and Sound
  • Importing and Setting Sounds
  • Setting Sound Properties
  • Adding Sounds to Movies
  • Using the Sound Class
  • Project: Experimenting with Sound
  • Using Media Components
  • Working with Media Classes
  • NetStream Controls

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Adding Video and Sound - Adding Sounds to Movies


    (Page 4 of 9 )

    Once you have imported sound into a document's library, placing it into the movie is simple. Click the keyframe where you want the sound to begin playing. Then, in the Property Inspector, select the sound you want in the Sound drop-down menu (Figure 10.2 shows the sound "narration.avi Audio" in both the Library panel and in the Property Inspector). Next, you can choose either Event or Stream in the Sync drop-down menu. An event sound downloads completely before it begins playing and needs only a single frame. A stream sound, on the other hand, uses a progressive download method of playing and will start playing after only a few frames are downloaded, resulting in the sound beginning much sooner. In addition, a stream sound is tied to the Timeline. Whereas an event sound requires only a single frame, a stream sound requires frames for the entire sound. The playhead moves at the speed of the sound, and if the computer cannot draw the animation fast enough to keep up with the sound, Flash will skip frames to make it do so. Table 10.1 shows the differences between the two types of sound.

    Table 10.1 Stream and Event Sounds

    Sound

    Download

    Timeline Coordinated

    Frames Required

    Event

    Complete

    No

    One

    Stream

    Progressive

    Yes

    The number necessary to encompass the entire sound


    An event sound will play after the movie has stopped, whereas a stream sound stops as soon as the playhead stops. Therefore, long after a movie has reached its last frame or a stop() action, an event sound can keep on playing, even repeatedly.

    Besides selecting Event or Stream in the Sync drop-down menu, you can select the Start and Stop options. The Start and Stop options are typically used in pairs. One keyframe is used to start the sound, and another is used to stop the sound. Selecting the Start option without using a Stop option functions like selecting an event sound. You can also add a Stop option in the layer where you have placed your sound with an event or stream sound.

    The Repeat/Loop option's primary use is for looping event sounds. Loops simply repeat a sound a specified number of times, and they shouldn't be used with stream sounds. Using loop sounds is the main method employed to load high-quality music to a Flash movie at minimum load time costs. Basically, the idea is to use a single music loop that keeps repeating itself but sounds like a single continuous song. For example, a high-quality sound set at 44KHz that loops 12 times is loaded only once but plays music the length of time a single sound file 12 times its size would play. Thus, instead of having to reduce the quality of the music, the developer simply uses a single, shorter, high-quality music file that repeats itself. The smaller length of the musical piece is where file size is kept small, rather than sacrificing quality. However, this method is only successful when used with loops.

    Note: Free Sounds - You can download hundreds of different music loops free from http://www.flashkit.com.

    Using the Behaviors Panel to Load Sounds

    Using the Behaviors panel, you can load and play sounds from external sources or the library. You can stop sounds globally and stop specific sounds as well. Table 10.2 shows the behaviors available for sound.

    Table 10.2 Sound Behaviors

    Behavior

    Action

    Load Sound from Library

    Uses a linkage name to load and/or play sound imported to the library

    Load Streaming MP3 File

    Uses progressive download to load and/or play an external MP3 file

    Play Sound

    Plays sound identified by an instance name

    Stop All Sounds

    Stops all sounds on all layers

    Stop Sound

    Stops only sound identified by a linkage name and instance name


    Using the Behaviors panel to add sound and to start and stop it is quite simple. Use the following steps to set up and play a sound file for access by the code generated through the Behaviors panel:

    1. Import a sound file to the library.

    2. Select the sound file in the Library panel and, from the Library menu or context menu, select Linkage.

    3. In the Linkage Properties dialog box, check Export for ActionScript and provide an identifier (no spaces) for the sound.

    4. Place a Button component on the Stage and label it Play Sound. With the button selected, click the plus (+) button in the Behaviors panel and then select Sound, Load Sound from Library.

    5. In the Load Sound from Library dialog box, type the linkage name and then type some other name for the code to use as a sound instance reference. (Any name will do.) Check the check box labeled Play This Sound When Loaded. Before clicking the OK button, you might want to jot down the linkage and instance names because you will need them both in step 7.

    6. On a different layer, drag another Button component to the Stage and label it Stop Sound. With the button selected, click the plus (+) button in the Behaviors panel and then select Sound, Stop Sound from Library.

    7. In the Stop Sound dialog box, enter the same linkage name and sound instance name you used in the Load Sound from Library dialog box in step 5.

    Now test the movie. When you click the Play Sound button, you should hear the sound, and as soon as you click the Stop Sound button, the sound should stop.

    One of the more useful actions to quickly generate with the Behaviors panel is streaming external MP3 files. By using external streaming, you can lessen the size of the SWF file, thereby reducing file size and load time. Because external files that will be streamed in don't add to the file size of the document, you can use any size MP3 file you want, and it won't delay the loading of your document. (The process used to "stream" MP3 files is actually progressive downloading, but the term stream is used because when you select the behavior from the Behaviors panel, you select the option Load Streaming MP3 File.) However, once an MP3 begins to play, the audio must take a little time to load a portion into the buffer.

    This chapter is from Macromedia Flash MX Professional 2004, by Bill Sanders (Sams, 2004, ISBN: 0672326051). Check it out at your favorite bookstore today.

    Buy this book now.

     

    More Flash Articles
    More By Bill Sanders


       · Thanx for taking the time to write this verry useful tutorial.. you helped me so...
     

    FLASH ARTICLES

    - Critical Flash Vulnerability Heats Up the Web
    - More on Nonpersistent Client-Side Remote Sha...
    - Nonpersistent Client-Side Remote Shared Obje...
    - Using the Decorator Pattern for a Real Web S...
    - Using Concrete Decorator Classes
    - Delving More Deeply into the Decorator Patte...
    - The Decorator Pattern in Action
    - A Simple Decorator Pattern Example
    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT