- the Sound() class can now load .mp3 files.
// Create a new Sound object.
var music = new Sound();
// Load the mp3 sound. Second argument specifies
// sound type: streaming (true) or event (false).
music.loadSound("trance.mp3", true);
// Sound is still controllable. This mutes the sound.
music.setVolume(0);
// Add a couple of methods to the sound class that
// fade a sound in from 0-100% volume over its duration.
Sound.prototype.startFadeIn = function () {
this.volInterval = setInterval(this, "fadeIn", 10);
}
Sound.prototype.fadeIn = function () {
this.vol = Math.floor(this.position / this.duration * 100);
this.setVolume(this.vol);
// Stop calling fadeIn() if the sound has finished playing.
if (this.vol == 100) {
clearInterval(this.volInterval);
}
trace("volume: " + this.vol);
}
// Try our startFadeIn() method.
music.startFadeIn();