Sound scripting

Hi

I’ve put this scipting at the beginning of of my flash file, but now I want to add a music on/off button. One button. What scripting do I use for the button?

 
mySound.stop();
mySound = new Sound();
mySound.loadSound("sound_1.mp3", false);
mySound.setVolume(40);
mySound.start(0, 100000);

Hi?:whistle: Is my scripting wrong? Or what should I do?

on (release){
if (mySound.position>0) {
mySound.stop();// stops the sound
}
else {
mySound.start(0,100000);//starts playing }
}

It should work :). Tell me if it helps you.

on (release){
 if (mySound.position>0) {
 mySound.stop();
}
else { 
 mySound.start(0,100000);}
}

thanks alot, but the sound turns off, and won’t play again if you press the button again.:-/

Thanks for the help?

maybe you should use “play” instead of “start”?

nope, still don’t wanna play???:ne:
shouldn’t be so difficult, huh?
anybody know?

ok… my bad… sorry but haven’t tested that code.
The fact is that even if you stop the sound, sound.position remains the number of miliseconds the sound has been playing, and does not revert to 0 (as i supposed it would :p)

I put a variable that checks if the sound is playing… try this code

on (release) {
	if (mySound.isPlaying != false)
	{
		mySound.stop();
		mySound.isPlaying = false;
	}
	else
	{
		mySound.start(0, 100000);
		mySound.isPlaying=true;
	}
}

and where you start the sound you should also define the variable

mySound = new Sound();
mySound.loadSound("sound_1.mp3", false);
mySound.setVolume(40);
mySound.start(0, 100000);
[color=red]mySound.isPlaying = true;[/color]

Tell me if it works this time :wink:

THANKS ALOT!!! :hugegrin: IT WORKS!!

my pleasure :wink: