Playing sounds

Playing a loaded sound can be as simple as calling the Sound.play() method for a Sound object, as follows:

var snd:Sound = new Sound(new URLRequest("smallSound.mp3"));
snd.play();

When playing back sounds using ActionScript 3.0, you can perform the following operations:

To perform these operations during playback, use the SoundChannel, SoundMixer, and SoundTransform classes.

The SoundChannel class controls the playback of a single sound. The SoundChannel.position property can be thought of as a playhead, indicating the current point in the sound data that's being played.

When an application calls the Sound.play() method, a new instance of the SoundChannel class is created to control the playback.

Your application can play a sound from a specific starting position by passing that position, in terms of milliseconds, as the startTime parameter of the Sound.play() method. It can also specify a fixed number of times to repeat the sound in rapid succession by passing a numeric value in the loops parameter of the Sound.play() method.

When the Sound.play() method is called with both a startTime parameter and a loops parameter, the sound is played back repeatedly from the same starting point each time, as shown in the following code:

var snd:Sound = new Sound(new URLRequest("repeatingSound.mp3"));
snd.play(1000, 3);

In this example, the sound is played from a point one second after the start of the sound, three times in succession.

Subtopics

Pausing and resuming a sound
Monitoring playback
Stopping streaming sounds

Flash CS3


 

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

Current page: http://livedocs.adobe.com/flash/9.0/main/00000289.html