A button for ON/OFF music?!

on this site is a tutorial for making a button with the action ON music but i want to make a button that will be able to tot ON/OFF how can i make some one like that?

MZZl Chooku

Just add a “StopAllSounds” action on the button…

i don’t get it it’s not working at all

help

Oh I understand! You want a button that will do ON AND OFF, right?

I think you can do it with MovieClips and telltarget… Hmm… Let me think…

Oh! I know!

Create a MovieClip and put your button in it. Make TWO keyframes in the MC.

Name the first keyframe ON and the other OFF. (in the “frame” panel)

In the ON keyframe, put a frame action:

StopAllSounds;
Stop;

(No, it’s not a mistake, stop all sounds on the ON keyframe)

And in the OFF keyframe put your sound in the frame (“sound” panel) and put the Stop; action in the frame.

Now the button part:

In the ON keyframe make your button actions like this:

on(Release){
gotoAndStop(“OFF”);
}

And in the OFF keyframe:

on(Release){
gotoAndStop(“ON”);
}

I hope you get my point here…
If it doesn’t work, you might have to make FOUR keyframes instead of TWO:

First keyframe: “ON”
StopAllSounds;
(no stop; )

Second keyframe: no label
Stop;

Third keyframe: “OFF”
Sound/music (no actions)

Fourth keyframe: no label
Stop;

And in the buttons instead of gotoAndStop you do gotoAndPlay

Í’ve made a button in the first keyframe and layer and the actions you gave me in a nother layer but i’ve i put your actions in each keyframe it don’t work. what did i wrong?

1/ it depends on how you use the sound, is it a sound object linked from the library, or is it inside a clip?
2/if method 1, use a variable as a true/false flag with a test :button:
on(release){
if (flag){ //means if flag==true
sound.play;
flag=false;}else{
sound.stop; flag=true;}
3/if method 2, put your sound in a clip with an empty 1st frame with a stop action,
and with the button, (test flag first) tell this clip to play (if flag=true)+set flag to false, else tell clip to gotoAndStop(1) and set flag = false.

Does this help?

Now understand not one bit of it!!! :frowning:

Okay… We’ll assume the music is initially on.

Make it so that on frame 1 of your file, your movie clip containing the song (henceforth to be referred to as “music”) is told to:

gotoAndPlay (2);

I’m sure you’ve done that. What you need to do different, though, is add this line:

songplay = 1;

That will be your switch between the song playing and the song not playing. “1” means that the song is playing, “0” means that the song is not playing. Now, on the on/off button, take the script that you probably already have:

on (release)
{
tellTarget (music) {
gotoAndPlay (2);
}
}

and change it to:

on (release)
{
if (songplay == 0)
{
tellTarget (music) {
gotoAndPlay (2);
}
songplay = 1;
}
}

The “if” statement will make sure that the song isn’t currently playing.

The “songplay = 1” will tell Flash that the song is playing. Now you can add this script:

on (release)
{
if (songplay == 1)
{
stopAllSounds ();
tellTarget (music) {
gotoAndStop (1);
}
songplay = 0;
}
}

This time it’s been changed so that it only works if the music is playing.

The stopAllSound () command will stop the music from playing.

The gotoAndStop (1); command will stop the music from restarting.

The songplay = 0; command will tell Flash that the music will stop.

Does that help?

One thing to make sure of, by the way…

Your music file should be inside of an offscreen movie clip. The first frame in that movie clip should be a blank keyframe with a “Stop” action inside. The frames after that should contain the music.

THNX