
Sound.onSoundComplete() Event Handler
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
782
|
ActionScript Language Reference
Arguments
success A Boolean: true if the load succeeded; otherwise, false. If the sound file was
not found in a call to loadSound(), onLoad() is executed with a
success
parameter of false.
Description
The onLoad() event handler executes when a sound file has downloaded completely into
soundObject due to an earlier call to loadSound().TouseonLoad(), we assign it a callback
(i.e., a custom-made function) that performs the action we take when our sound loads
properly and/or the action we take when the load attempt fails. For example:
// Create the Sound object
carSound = new Sound();
// Assign a callback
carSound.onLoad = function (success) {
if (success) {
// Respond to completed sound load operation here
} else {
// Execute load-failure code here
}
}
If the loaded sound is an event sound, we can use onLoad() to start playing it, as follows:
carSound = new Sound();
carSound.onLoad = function (success) {
if (success) {
this.start();
} else {
displayLoadError();
}
}
carSound.loadSound("http://www.somesite.com/sounds/driving.mp3", false);
The onLoad() callback handler should be defined before the call to loadSound() is made.
Notice that from the body of the onLoad() handler we can refer to our sound object with
the
this keyword. ...