Mute music button in navbar

A user rolls over my pre-made navigation menu embed in an html page. The menu pops up, then I want a toggle button for turning music on or off. Like here.

I don’t want volume control, or two seperate buttons for on and off. I can’t seem to find a simple tutorial for this! I already made a 10-second sound loop. I’ve been working with Flash for about one month.

Any help will bring bushels of gold.

Wynk

Well, it is pretty simple.

Create a movie clip symbol. Name it whatever.

Inside that movie clip symbol have 2 frames both with stop() actions.

Create the off button in frame 1, and the on button in frame 2.

Now go back to the main timeline where your movie clip symbol is (so you aren’t at the 2 frames anymore) Right click on the movie clip symbol and open the Actions window.

Now on your movie clip, since MX can use button handlers on movie clips, add these actions…

on (release) {
	if (!trip) {
		stopAllSounds();
		this.gotoAndStop(2);
		trip = true;
	} else {
		this.gotoAndStop(1);
		trip = false;
	}
}

Now with this method… you will have to re-enter your clip, and click on Frame 1, then drag an instance of your music from the library and drag it onto frame 1 and set the amount of loops in the properties panel for the frame (CTRL+F3 to open properties panel).

Or you can add the sound through AS, but this will make your sound file load BEFORE your preloader, and I don’t know the way around that, but it is a pain.

But that code for your button will still be the same, but you will need to add more actions to frame 1 of your movie clip symbol.

So Frame 1 of your movie clip symbol should look like this…

mySound = new Sound(this);
   mySound.attachSound("music");
   mySound.start(0, 99);
   stop();

And to get it to work you will have to right click on your music file in the flash library (CTRL+L) and select “Linkage” and check the box for “Export for Actionscript” and give it the name “music” (no quotes).

I hope this helps :slight_smile:

Note: Oh yeah, the 99 in the mySound.start is the amount of times to loop, 99 is the max no matter what. The 0 is the offset, and it is the number of seconds into the sound it will actually start to play.

Wow, great help, and quick reply, thanks. I went through your directions and they worked great. But I still gotsa problem:

I want the sound to start playing on my site right away, which your directions showed me how to do. But I want a user to open my expandable nav menu and find that sound control in there. Except, when I put the sound control in my nav menu, it does not remember what the user had previously set it to and also, it does not play music right away until the nav menu plays. And if the user clicks the sound control again, the sound begins to overlap with another copy of itself.

My nav menu has three parts within about 10 frames. Frame 1: Closed --> user clicks it --> Frames 2-5: Opens --> user clicks again --> Frame 6-10: Closed and loop back to Frame 1.

Bah. Maybe I’ll just put the sound control its own swf file and embed that elsewhere in my html.

:sigh:

*Originally posted by Wynk *
**Bah. Maybe I’ll just put the sound control its own swf file and embed that elsewhere in my html.

:sigh: **

Well instead of doing that… why not just leave the sound button outside of the menu?

I wish I could help, but I have to go, it is 4:30am here and I am beat! I hate to leave you halfway resolved with this, but maybe someone will come along and figure out what to do… or if I can think of something else to do tomorrow I will post it.