Home arrow Flash arrow Page 5 - 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 - Using the Sound Class
(Page 5 of 9 )

The code generated by the Behaviors panel shows how Flash Pro uses the many different elements of the Sound class. Tables 10.3–10.5 summarize the methods, properties, and events, respectively, of the Sound class.

Table 10.3 Sound Class Methods

Method

Actions

soundInst.attachSound("id")

Attaches the sound identified by the linkage name id to the instance.

soundInst.getBytesLoaded()

Returns the number of bytes in the sound instance that's currently loaded.

soundInst.getBytesTotal()

Returns the total number of bytes in the sound instance.

soundInst.getPan()

Returns the current pan value established by setPan().

soundInst.getTransform()

Returns the value from the last setTransform() call.

soundInst.getVolume()

Returns the current volume setting.

soundInst.loadSound("url", Boolean)

Loads the MP3 file identified by url with the option of streaming (Boolean true) or event (Boolean false).

soundInst.setPan(n)

The pan value (n) is set in terms of negative values up to –100 for the left speaker and positive values up to 100 for the right speaker. Mid balance is 0.

soundInst.setTransform(Obj)

Establishes the amount of the two channels that will be played in left and right speakers. (Obj is an object containing the channel properties for left/right speakers.)

soundInst.setVolume(n)

The volume (n) can be set from 0 to 100, where 0 indicates the sound is off.

soundInst.start(s,l)

The sound begins playing with these optional parameters: start position in seconds (s) and number of times to loop (l).

soundInst.stop()

Only stops the sound instance's sound.


Table 10.4 Sound Class Properties

Property

Characteristics

soundInst.duration

Returns the number of milliseconds in a sound instance.

soundInst.id3.tagName

A read-only property to access different ID3 1.0/2.0 tags (tagName) in an MP3's metadata.

soundInst.position

Returns the number of milliseconds for which a sound has been playing.


Table 10.5 Sound Class Events

Event

Description

soundInst.onID3

Fires after the load sequence and ID3 data become available.

soundInst.onLoad

When a sound is loaded, the event fires.

soundInst.onSoundComplete

Fires once the sound has stopped playing.


The Sound class provides two methods to access sound: attachSound() and loadSound(). When you use attachSound(), you need to first import a sound into the Library panel and give it a linkage name. Using loadSound(), you can load the sound file directly from the server, either as an event sound or a stream sound. When you select a stream sound, the sound begins playing shortly after the loading begins.

All instances of the Sound class must first be instantiated using the Sound constructor, such as in the following line:

var soundBarrier:Sound = new Sound();

Once the Sound class is instantiated, its different methods, properties, and events can be attached to the instance. Using the Sound class, you have far more control over sound than with any other technique available in Flash Pro.

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 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials