To make a button that stops or starts a music loop (variable name: “music”) depending on whether the music is playing already, create a true/false variable (in this case, “musicplaying”) and change it with the button:
on (release) {
if (musicplaying == true) {
music.stop();
musicplaying = false;
} else {
music.stop(); // guard against overlap
music.start(0, 100);
musicplaying = true;
}
}
This way, you don’t need to do any checking to figure out whether the sound is playing. You also need only one button, not two.
This script works with an attached or loaded sound, with the ID “music.” When you start the sound file for the first time, you must initialize (set) the variable “musicplaying” to true:
music.start(0,100);
var musicplaying = true;
The script for a fully functional pause button, which stops and starts at the same spot in the audio file, is explained in the book.




March 23, 2010 at 9:56 am
Great tut!
September 16, 2010 at 9:59 pm
hi i learn how to create toggle button in flash but what if you want to use in webisite
or use in Dreamweaver for website..
thanks