Flash
  Home arrow Flash arrow Page 6 - 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 - Project: Experimenting with Sound


    (Page 6 of 9 )

    To show you how several Sound class features can be employed, the following application uses UI component buttons to start and stop a sound and sliders to control the volume and pan. A single MP3 file named jazz1.mp3 is employed, but any MP3 file can be used in its place. The following steps show how to create the application:

    1. In a new Flash document, create six layers named, from top to bottom, Actions, Labels, Buttons, Levers, Grooves, and Background. Provide a gray background color (#A6A6A6).

    2. Using Figure 10.5 as a guide, in the Grooves layer draw a vertical line with settings H=100, X=100, Y=140, and a horizontal line with settings W=200, X=200, Y=200 using color code #A699E6. Then in the Background layer, add solid black rectangles. In the

      Buttons layer, drag two UI component buttons to the stage, providing the labels Start Stream to the top button and Stop Sound to the bottom button. Add the instance name stream_btn to the top button and stop_btn to the bottom button.

      In the Labels layers, add static text labels as shown in Figure 10.5. Also, in the Labels layer centered beneath the Pan label, add a dynamic text field and provide the instance name soundStatus_txt.

      sanders
      Figure 10.5
      Sound controllers.

    3. Select the Levers layer and draw a rectangle with the dimensions W=31, H=8. Select the rectangle and press F8 to convert it into a movie clip with the name lever. Give it the instance name vol_mc. From the Library panel, drag a second instance of the movie clip. Rotate the second lever 90 degrees, and give it the instance name pan_mc. Place the vol_mc instance at the top of the vertical groove line and place pan_mc in the middle of the horizontal groove line, as shown in Figure 10.5.

    4. Click the first frame of the Actions layer. Open the Actions panel and add the following script:

      //Instantiate sound instance
      var soundHere:Sound = new Sound();
      //Load a streaming sound
      stream_btn.onPress = function() {
      soundHere.loadSound("jazz1.mp3", true);
      };
      soundHere.onLoad = function() {
      soundStatus_txt.text = "Sound streaming";
      };
      //Stop the streaming sound
      stop_btn.onPress = function() {
      soundHere.stop();
      soundStatus_txt.text = "Sound stopped";
      };
      //Volume Control
      vol_mc.onPress = function() {
      this.startDrag(false, 115, 140, 115, 240);
      };
      vol_mc.onRelease = function() {
      stopDrag();
      };
      var hearVol:Object = new Object();
      hearVol.onMouseMove = function() {
      soundHere.setVolume(240-vol_mc._y);
      };
      Mouse.addListener(hearVol);
      //Pan Control
      pan_mc.onPress = function() {
      this.startDrag(false, 195, 184.5, 395, 184.5);
      };
      pan_mc.onRelease = function() {
      stopDrag();
      };
      var hearPan:Object = new Object();
      hearPan.onMouseMove = function() {
      soundHere.setPan(295-pan_mc._x);
      };
      Mouse.addListener(hearPan);
      //Signal end of sound
      soundHere.onSoundComplete = function() {
      soundStatus_txt.text = "Sound finished";
      };

    The volume slider control is set to generate values from 0 to 100, and the pan slider control is set to generate values from –100 to 100. The two buttons invoke methods to begin the progressive download (streaming) and to stop the sound instance. The onLoad() event handler indicates that the progressive download has "loaded" as soon as enough of the file has entered the buffer to begin playing. Therefore, only a small part of a stream sound needs to be loaded to fire the onLoad() event handler, whereas an event sound must be fully loaded to invoke the same event.

    In tests with the sample file (a 940KB MP3 music file), the buffering time ranged from 3 to 7 seconds on high-speed connections (cable and DSL). The longer test periods were on DSL lines between the Eastern U.S. and Europe, whereas the shorter time was to and from an East Coast U.S. city. With slower Internet speeds, the buffering time could increase significantly, and a "buffering" message lets the user know that something is happening while he or she is waiting for the file to begin playing.

    A new feature added to the Sound class is the ID3 property and event handler. ID3 information is optionally added to an MP3 file, but if the information is available, you can incorporate it into your document. The read-only information in the ID3 property can be used in conjunction with the onID3 event handler in the following format:

    soundInstance.onID3 = function() {
    ID3info_txt.text = soundInstance.id3.tag;
    }

    With 47 different ID3 properties (tags) available, from album name to the name and the length of the song, you can find a good deal of information you may want to incorporate into your Flash document. Figure 10.6 shows a partial list of the ID3 properties you can select from the Sound class pop-up menu.

    sanders

    Figure 10.6
    A pop-up menu shows the different ID3 properties.

    Many MP3 files have minimal or no ID3 information at all. When no ID3 information is detected using the onID3 event handler, you will either get an "undefined" response, indicating that some ID3 information is in the MP3 file but not the property you requested, or an "empty" ID3 response, indicating that no ID3 information at all is available in the file.

    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 3 Hosted by Hostway
    Stay green...Green IT