Sound.onLoad( ) Event Handler | Flash 6 |
occurs when an external sound finishes loading |
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.
The onLoad( ) event handler executes when a sound file has downloaded completely into soundObject due to an earlier call to loadSound( ). To use onLoad( ), 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.
Before a sound has fully loaded, we can check its download progress with getBytesLoaded( ).
The duration, position, and id3 Sound properties are not initially available from within an onLoad( ) handler. See those property entries for details and workarounds.
Sound.getBytesLoaded( ), Sound.getBytesTotal( ), Sound.loadSound( ), Sound.onSoundComplete( )