A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Create Mute Button

  1. #1
    Junior Member
    Join Date
    Oct 2001
    Posts
    11
    Could anyone please tell me how to create a mute button in flash so that when its clicked all sounds are muted, however, when clicked again all sounds resume but without starting again from the beginning. Thanks.

  2. #2
    United States Presidential Hopeful in 2028
    Join Date
    Dec 2000
    Posts
    756
    You can use the stopAllSounds action to mute everything.

    Restarting it from the same place may not be possible in a file size that is reasonable. You could do it with streaming sound by just having the pleayhead stop, but if you are trying to use it as background music then streaming sound is much larger when looping than event sound since event sound only uses one instance of the sound to loop, but streaming sound will add to the file size each time it is looped.

    I have a tutorial on selectable background music at Milk in a Bag if that would be of any help.

  3. #3
    Member
    Join Date
    Jun 2001
    Posts
    45
    Hi!

    Best way to do that is creating and independet movie clip for sound. I would do that at the following way:

    First of all you need 2 layers (sound and buttons). Each layer must to have 2 keyframes.

    At first keyframe of sound layer import the sound you want and set loop = 99 so the sound will loop 99 times and put a stop action.

    In second keyframe put the following code:

    stopAllSounds ();
    stop ();

    In the first keyframe of buttons layer you must to put a stop button with the following code:

    on (release) {
    gotoAndStop (2);
    }

    And at the second keyframe of buttons layer yo must to create a start button with the following code:

    on (release) {
    gotoAndStop (1);
    }

    And that´s all. You have your sound movie ready!

    ;-)

    Lester.

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    1

    How to make this work in movie with more than 2 frames?

    This is working fine, but how to use this in a SWF clip where this button is to be used? It seems to work as a 2 frame movie only.

  5. #5
    Senior Member
    Join Date
    May 2008
    Posts
    332
    Not exactly sure what type of sound you are using but here is some AS for a mute button, which mutes but does not stop the sound. When clicked again it un-mutes, and continues playing at whatever point the sound has reached.
    Code:
    var jukebox:Sound = new Sound();
    some other stuff goes here
    
    //-------MUSIC PLAYER CONTROLS--------//
    var currentPosition:Number = 0;
    var paused:Boolean = false;
    mute_btn.onRelease = function() {
    	if (jukebox.getVolume() > 0) {
    		jukebox.setVolume(0);
    	}
    	else
    	{
    		jukebox.setVolume(100);
    	}
    }
    This is from a 1 frame mp3 player. The button is just a simple button with the action in the actions layer of the main timeline. Maybe you can adapt something from this.
    Best wishes,
    EfV

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center