fadein+loop af sound
HejJeg bruger følgende script til at hente/preloade musik i flash... men jeg har også brug for at fade musiken ind og derefter loope den uden fadeup.
var mainTimeline = this;
/*
* Method: Sound.checkLoadProgress()
* Desc: Checks progress of a load().
* Called only by preload(). Reports download progress
* by invoking a custom Sound.onBytesLoaded() handler.
*/
Sound.prototype.checkLoadProgress = function () {
// Check how many kilobytes have loaded.
var kbLoaded = Math.floor(this.getBytesLoaded()/1024);
// Check the size of the file loading, in kilobytes.
var kbTotal = Math.floor(this.getBytesTotal()/1024);
// Calculate the percent complete.
var percentDone = isNaN(Math.floor(kbLoaded/kbTotal * 100)) ?
0 : Math.floor(kbLoaded/kbTotal * 100);
// Execute the onBytesLoaded() callback, which
// typically would display load progress.
this.onBytesLoaded(this.getBytesLoaded(),
this.getBytesTotal(),
kbLoaded,
kbTotal,
percentDone);
}
/*
* Method: Sound.clearLoadCheck()
* Desc: Cancels an interval calling checkLoadProgress().
*/
Sound.prototype.clearLoadCheck = function () {
// If there is a load interval for this Sound object...
if (this.loaderID) {
// ...stop calling it.
clearInterval(this.loaderID);
}
}
/*
* Method: Sound.preloadSound()
* Desc: Begins the download of a sound file and executes
* checkLoadProgress() every 200ms until the file has loaded.
* Parameters are the same as Sound.loadSound().
*/
Sound.prototype.preloadSound = function (url, isStreaming) {
// Always stop any previous preload before proceeding.
this.clearLoadCheck();
// Call checkLoadProgress() every 200 milliseconds.
this.loaderID = setInterval(this, "checkLoadProgress", 200);
// Load the Sound file.
this.loadSound(url, isStreaming);
}
// =================
// Usage
// =================
// Create a sound object.
lyd = new Sound();
// Assign an onLoad() callback.
lyd.onLoad = function (success) {
// Cancel the preload interval (REQUIRED!).
this.clearLoadCheck();
// If the load was successful...
if (success) {
// ...use the new Sound. For example, if the loaded
// sound is an event sound, we can start it like this:
// this.start();
mainTimeline.loadMsg_txt.text = "100 % loaded...";
_parent.gotoAndStop(2);
} else {
// ...otherwise, perform failure operations.
mainTimeline.loadMsg_txt.text = "Load failed.";
}
}
// Assign an onBytesLoaded() callback. This is where each
// individual Sound object can decide what to do
// with the preload information.
lyd.onBytesLoaded = function (bytesLoaded, bytesTotal, kbLoaded, kbTotal, percentLoaded) {
mainTimeline.loadMsg_txt.text = percentLoaded + " % loaded...";
}
// Load a streaming sound.
lyd.preloadSound("flash/sound/cosmopolitan.mp3", true);
lyd.onSoundComplete = function() {
this.preloadSound("flash/sound/cosmopolitan.mp3", true);
}
håber ikke det kan fylde for meget =)
men det er egentlig bare en fadein over 5-10 sekunder jeg har brug for så man ikke bare får max volume fra starten.
/Snig
