Sound Class

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Sound Class Flash 6

control over sounds in a movie and external sound loading toolsFlash 5; enhanced in

Constructor

new Sound() new Sound(target)

Arguments

target

A string indicating the path to the movie clip or document level whose sound is to be controlled. It can also be a reference to a movie clip or document level (references are converted to paths when used in a string context).

Properties

duration

The total length of the sound, in milliseconds.

id3

Access to the ID3 tags of an MP3 file.

position

The length of time the sound has played, in milliseconds.

Methods

attachSound( )

Associate a sound from the Library with a Sound instance.

getBytesLoaded( )

The number of downloaded bytes of an external sound file.

getBytesTotal( )

The physical disk size of an external sound file, in bytes.

getPan( )

Retrieve the current pan setting.

getTransform( )

Determine the current distribution of the channels of a sound to the left and right speakers (i.e., balance).

getVolume( )

Retrieve the current volume.

loadSound( )

Download an external sound file into the Player.

setPan( )

Set the pan across a sound's left and right channels.

setTransform( )

Distribute the left and right channels between the left and right speakers (i.e., balance).

setVolume( )

Set the sound volume.

start( )

Start playing an attached or loaded event sound.

stop( )

Silence all sounds or silence a specified attached or loaded sound.

Event Handlers

onLoad( )

Occurs when an external sound finishes loading.

onSoundComplete( )

Occurs when a sound finishes playing.

Description

Objects of the Sound class are used to load external sounds and control both existing and loaded sounds in a movie. Sound objects can control:

  • All the sounds in the Flash Player

  • All the sounds in a particular movie clip instance or main movie (including all sounds in any nested clips)

  • An individual programmatically attached or downloaded sound

To create a Sound object that controls all the sounds in the Player (including sounds in .swf files on document levels), use the Sound constructor without any parameters. For example:

myGlobalSound = new Sound();

To create a Sound object that controls all the sounds in a particular clip or main movie, supply a target parameter indicating the clip or movie to control. Note that this also controls sounds in clips nested within target. For example:

spaceshipSound = new Sound("spaceship");  // Control sounds in spaceship clip mainSound      = new Sound("_root");      // Control sounds on main timeline

To make an individual sound that can be started, stopped, and looped independently, create any kind of Sound object, and then add a sound to it using the attachSound( ) or loadSound( ) method.

To load an external sound file into a Sound object, use loadSound( ). A loading sound's progress can be monitored with getBytesLoaded( ), getBytesTotal( ), and onLoad( ).

Flash does not provide access to, or control over, sound frequency or pitch information, but Flash does expose the length of a sound (duration) and the elapsed time (position).

Flash can play a maximum of eight individual sounds simultaneously. When loaded via attachSound( ), each simultaneous sound needs its own Sound instance.

A sound does not stop playing when the object that controls it is deleted. Use Sound.stop( ) to halt the playback of loaded or attached sounds.

See Also

capabilities.hasAudio, stopAllSounds( ); _soundbuftime

     
       About Safari   |   Terms of Service   |   Privacy Policy   |   Contact Us   |   Help   |   Submit a Problem
    Copyright 2002 O'Reilly & Associates, Inc. All rights reserved.
    1005 Gravenstein Highway North
    Sebastopol, CA 95472
     


    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net