Home arrow Flash arrow Page 8 - Adding Video and Sound
FLASH

Adding Video and Sound


The three major types of sounds for use in Flash movies include music, sound effects, and narration. Learn how to add sound to Flash movies, how to use media components and work with media classes (from Macromedia Flash MX Professional 2004 by Bill Sanders, 2004, Sams, ISBN 0672326051).

Author Info:
By: Bill Sanders
Rating: 4 stars4 stars4 stars4 stars4 stars / 31
July 12, 2004
TABLE OF CONTENTS:
  1. · Adding Video and Sound
  2. · Importing and Setting Sounds
  3. · Setting Sound Properties
  4. · Adding Sounds to Movies
  5. · Using the Sound Class
  6. · Project: Experimenting with Sound
  7. · Using Media Components
  8. · Working with Media Classes
  9. · NetStream Controls

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.

 
blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- 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

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials