View comments | RSS feed

Sound class

Availability

Flash Player 5.

Description

The Sound class lets you control sound in a movie. You can add sounds to a movie clip from the library while the movie is playing and control those sounds. If you do not specify a target when you create a new Sound object, you can use the methods to control sound for the whole movie.

You must use the constructor new Sound to create a Sound object before calling the methods of the Sound class.

Method summary for the Sound class

Method Description
Sound.attachSound()

Attaches the sound specified in the parameter.

Sound.getBytesLoaded()

Returns the number of bytes loaded for the specified sound.

Sound.getBytesTotal()

Returns the size of the sound in bytes.

Sound.getPan()

Returns the value of the previous setPan() call.

Sound.getTransform()

Returns the value of the previous setTransform() call.

Sound.getVolume()

Returns the value of the previous setVolume() call.

Sound.loadSound()

Loads an MP3 file into Flash Player.

Sound.setPan()

Sets the left/right balance of the sound.

Sound.setTransform()

Sets the amount of each channel, left and right, to be played in each speaker.

Sound.setVolume()

Sets the volume level for a sound.

Sound.start()

Starts playing a sound from the beginning or, optionally, from an offset point set in the parameter.

Sound.stop()

Stops the specified sound or all sounds currently playing.

Property summary for the Sound class

Property Description
Sound.duration

Read-only; the length of a sound, in milliseconds.

Sound.id3

Read-only; provides access to the metadata that is part of an MP3 file.

Sound.position

Read-only; the number of milliseconds a sound has been playing.

Event handler summary for the Sound class

Event handler Description
Sound.onID3

Invoked each time new ID3 data is available.

Sound.onLoad

Invoked when a sound loads.

Sound.onSoundComplete

Invoked when a sound stops playing.

Constructor for the Sound class

Availability

Flash Player 5.

Usage

new Sound([target:Object]) : Sound

Parameters

target The movie clip instance on which the Sound object operates. This parameter is optional.

Returns

A reference to a Sound object.

Description

Constructor; creates a new Sound object for a specified movie clip. If you do not specify a target instance, the Sound object controls all of the sounds in the movie.

Example

The following example creates a new Sound object called global_sound. The second line calls setVolume() and adjusts the volume on all sounds in the movie to 50%.

var global_sound:Sound = new Sound();
global_sound.setVolume(50);

The following example creates a new Sound object, passes it the target movie clip my_mc, and calls the start method, which starts any sound in my_mc.

var movie_sound:Sound = new Sound(my_mc);
movie_sound.start();

Comments


Chris Porro said on May 12, 2005 at 12:32 PM :
i have a question about targeting a sound object.

here is my code:

this.createEmptyMovieClip ("mc_rasta_sound", 1);
var rasta_sounds:Sound = new Sound ("mc_rasta_sound");
rasta_sounds.attachSound ("bang-01.mp3");

this works fine and i am able too play this sound object with...

rasta_sounds.start (0, 1000);

that is IF i call start from the same level as my contructor code (in this
case the main timeline). if i try to start this sound from anywhere else in
my movie (say from a nested clip) it doesn't start. even when i use...

_root.rasta_sounds.start (0, 1000);

any ideas?
de:jay said on May 15, 2005 at 4:25 PM :
Have you tried, _root.mc_rasta_sound.rasta_sounds.start (0, 1000);?


My Question is how do you clear a sound object? I understand the sound.stop(); but this doesn't seemt to clear out the sound obj. Do i need to overwrite the sound obj's var?
No screen name said on Jun 20, 2005 at 8:45 PM :
This seems to be a bug.

Subtracting the last stop time from the reported position doesn't work either because the position variable can only hold up to 364407 before it stops dead (in my experience). Thats just over 6min before the clock stops working altogether...

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001671.html