FORUMS: list search recent posts

Sound fade out onPress event to another scene

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Char Cole
Sound fade out onPress event to another scene
on Jun 9, 2008 at 1:23:07 pm

Sorry to be a bother again but I have been struggling with this all night.

Basically I have a home scene that starts to play music when it opens. When I click on a button to go to another scene I want it to fade out so that in the new scene I can play another song. I would rather it didnt just cut off by using the stopAllSounds option. I would like it to just transition smoothly off and into the new song on the new scene.

Here is the code I am working with:

// initiate sound
music = new Sound();
music.attachSound("mama");
music.start(0, 999999);
// set the volume of the sound to zero
music.setVolume(0);
// set a variable named 'vol'
vol = 0;
// set another variable named 'fade', putting a setinterval function in it
fade = setinterval(fadeIn, 100);
// set the initial fade in function
function fadeIn() {
// fade the sound in with an increment of 3 in the variable 'vol'
vol += 3;
music.setVolume(vol);
// put an if condition to restrict the increment in volume after it reaches to 100
if (vol>=100) {
clearInterval(fade);
// create the 'step' variable
step = 1;
// create the 'fade' variable
Fade = 0;
}
}
// function executed on onEnterFrame
_root.onEnterFrame = function() {
// set fade out
if (Fade == 1) {
vol = vol-step;
if (vol<0) {
vol = 0;
}
music.setVolume(vol);
// set fade in
} else {
vol = vol+step;
if (vol>100) {
vol = 100;
}
music.setVolume(vol);
}
};
*************************************
When I comment out all but the:
// initiate sound
music = new Sound();
music.attachSound("mama");
music.start(0, 999999);

It will load the song but of course doesnt stop or fade. When I put it back in and test it the music wont play.

I am using CS3, exporting for flash 8 and using ActionScript 2.0 (The final product is for my mother and she has an older computer). Any ideas? Thanks!

Char

"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]