
Sound.onLoad() Event Handler
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
781
Flash can play a maximum of eight individual sounds simultaneously. When loaded via
attachSound(), each sound needs its own Sound instance.
To determine whether the Flash Player being used supports MP3 audio playback, use
System.capabilities.hasMP3.
Usage
Compressed MP3 files often contain minor imperfections (such as an initial delay) that
affect looped playback in Flash. To compensate, a loaded event sound can be offset by a
small amount, as follows:
loopSound.start(0.05, 3);
However, this technique does not account for any ending silence on the sound, so results
may vary. For best loop performance, use ADPCM or MP3 compression directly in Flash
and attach the loop sound from the Library using attachSound().
Example
To load a sound, we first create a Sound object, then call the loadSound() method. Often,
it’s also a good idea to respond to the completion of the sound’s download by defining a
callback function for onLoad(), as shown in the following example. First, we load an event
sound; notice that the onLoad() handler must be defined before the loadSound() call:
// Create a Sound object
music = new Sound();
// Define an onLoad() callback function for our object
music.onLoad = function () {
// Place code here to respond to ...