Flash
  Home arrow Flash arrow Page 8 - 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 - Working with Media Classes


    (Page 8 of 9 )

    Using ActionScript 2.0's new media classes, you can effect far more precision than with any of the other tools available in Flash Pro. However, at the same time, many of the classes require Flash Communication Server for them to be of much use. Included in the media classes are the following:

    • Camera

    • Microphone

    • NetConnection

    • NetStream

    • Sound

    • Video

    In looking at the classes within the media classes' ActionScript folder, you can see that only a portion can be applied without other programs. The first part of this chapter covered the Sound class, so that class will not be repeated here. The Camera and Microphone classes primarily are made up of a large number of read-only properties, and the methods and properties that allow writing are of little value without outward streaming or recording. Without Flash Communication Server, the only streaming that occurs is the progressive downloads of FLV files. Therefore, the remainder of this chapter shows how to employ the NetConnection, NetStream, and Video classes.


    Which Media Component? - Some designers may wonder, why have the MediaController in the mix of media components? If you need a controller, just use the MediaPlayback, and if you don't, use the MediaDisplay. Seems like a no-brainer!

    However, after some work with these components, you'll see that the separate display and controller turns out to be a very good idea. First, when you set the size of the display, you get exactly what you need for the design, and you maintain the 4:3 aspect ratio of the video. Once it has been sized, you can then add the controller separately. When you size the MediaPlayback component, though, the size includes both the display screen and the attached controller, so it's difficult to get an exact fit.

    Second, unlike the MediaPlayback component, the MediaController is not connected to the display screen, so you can put it where you want. You can even change its orientation from horizontal to vertical if needed. So what may at first appear to be an unnecessary media component turns out to be an important design component.


     Playing FLV Files with ActionScript 2.0

    Prior to ActionScript 2.0, the only way you were able to play an FLV file was using Flash Communication Server. With Flash Pro using script, you can create very small files that can progressively download and display an FLV file. For example, a simple movie that steams an FLV file can be created in less than 1KB, whereas the minimum using components is about 67KB.

    To get started, all you need on the Stage is a single embedded video object. The following steps show how to use the NetConnection and NetStream classes in conjunction with the Video class to display an FLV video:

    1. Open a new Flash document and then open the Library panel. Add a total of three layers named, from top to bottom, Actions, Video, and Background.

    2. In the Library panel, open the panel's pop-up menu and select New Video. An embedded video icon appears in the library.

    3. Open the Color Mixer and in the large color pane, add the color #5C0B08 (dark maroon). Then open the Color Mixer's pop-up menu and select Add Swatch. Do the same thing with the colors #D4B707 (dark mustard) and #EADFC2 (light tan). Use the light tan as the background color for the movie.

    4. Select the Background layer. In the middle of the Stage draw a rectangle with a dark mustard 3.75 stroke and a dark maroon fill. Use the Align tools to center the rectangle in the middle of the Stage. Lock the Background layer.

    5. Select the Video layer and then drag an instance of the embedded video object to the center of the stage. In the Property Inspector, lock the object dimensions and change the W value to 300. (The H value should automatically change to 225.) Then, using the Align panel tools, center the Embedded Video object in the middle of the stage and give it the instance name flashVid_video.

    6. Select the Actions layer and in the Actions panel, add the following script, substituting media5.flv for an FLV file in the same folder where you saved your FLA file:

      //Make NetConnection
      var makeConn_nc:NetConnection = new NetConnection(); makeConn_nc.connect(null);
      //New NetStream
      var netWork_ns:NetStream = new NetStream(makeConn_nc);
      //Connect to Video instance
      flashVid_video.attachVideo(netWork_ns);
      netWork_ns.play("media5.flv");

    Once you save the FLA file, test it. Its size is only 291 bytes (that's bytes, not kilobytes!). Because bandwidth is measured in bits instead of bytes, multiply the size by 8 to get the number of bits being shipped over the Internet—only about 2.3Kb—not even enough to get a 56K phone modem wheezing. The main bandwidth usage will come from progressively downloading the FLV file, but because this is done progressively, only a little at a time has to be sent and processed.

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