Questo e' un esempio completo su un solo pulsante ( fa sia fadein che fadeout ) , poi te lo gestisci o modifichi come ti pare ...
testalo con un file loop.mp3 sulla stessa cartella.
codice:
stop();
// funzione di riferimento.
// ricordarsi che utilizza l' interval nella var fadeInterval
// ( Sound.fadeInterval )
soundFade = function( who, how ) {
var thisVolume = who.getVolume();
if( how.toLowerCase() == "in" ) {
if( thisVolume < 100 ) {
who.setVolume( thisVolume + 1 );
}
else {
who.setVolume( 100 );
clearInterval( who.fadeInterval );
}
}
else if( how.toLowerCase() == "out" ) {
if( thisVolume > 0 ) {
who.setVolume( thisVolume - 1 );
}
else {
who.setVolume( 0 );
clearInterval( who.fadeInterval );
}
}
}
// funzione qualunque per abilitare un tasto con nome istanza
// soundBtn che se premuto parte e fa fadein, altrimenti fade out ...
function enableSound( who ) {
soundBtn.onPress = function() {
if( who.fadeInterval != undefined ) {
clearInterval( who.fadeInterval );
}
if( this.pushed ) {
who.fadeInterval = setInterval( soundFade, 20, who, "out" );
}
else {
who.fadeInterval = setInterval( soundFade, 20, who, "in" );
}
this.pushed = !this.pushed;
}
}
// funzione che assegna, imposta l' onLoad e carica il suono
var mySound = new Sound( this );
mySound.onLoad = function() {
this.setVolume( 0 );
this.start( 0, 999 );
// richiamo al bottone per la gestione
// ... se non clicki, non parte il fadein
enableSound( this );
}
mySound.loadSound( "loop.mp3" );
Mi spiace solo che non riesci ad adattare quello che e' sempre e comunque lo stesso codice per situazioni differenti.