Hey guys, I'm having trouble getting any sound to play in my second scene. I'm using actionscript in the first scene to fade in the music, then fade it out after they click the button.
Here's the code on layer 1:
Actionscript Code:
music = new Sound();
music.attachSound("background");
music.setVolume(0);
music.start(0,1);
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 = 3;
// create the 'fade' variable
fade2 = 0;
}
}
// create the fade in and out function
// function executed on onEnterFrame
_root.onEnterFrame = function() {
// set fade out
if (fade2 == 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);
}
}
This code does exactly what it should (fades the music in, then fades it out when the user clicks the button)
Here's the code for the button:
Actionscript Code:
stop();
play_btn.onRelease = function(){
(_root.fade2=!_root.fade2) ? 0 : 1;
_root.gotoAndPlay(241); //Fades out and ends, going to scene 2
}
Problem: I tried adding a sound to the stage in scene 2 but nothing plays when i test the movie, expect for the music in scene 1. I tried creating another sound object in the first frame of scene 2 but i get the same result. Any ideas why it won't work?