2 Replies Latest reply on Oct 4, 2006 9:23 AM by MultiDesign01

    toggle music

    MultiDesign01
      I am trying to create a music on/off button. I only want one button to do both functions. I added the below ActionScript to the button. The music turns off when the button is pressed, but when pressed again, the music doesn't turn back on. I've created a linkage for the music MP3 (mainMusicID) and defined it in an opening frame using ActionScript, calling it "mainMusic". What am I missing?

      on (press){
      if (playing!=true) {
      mainMusic.start(0,999);
      playing=true; }
      mainMusic.stop();
      playing=false;
      }
        • 1. Re: toggle music
          Level 7
          put this on the main timeline.
          assuming the instance name of your button is myBtn:

          playOn = 0;
          myBtn.onRelease = function(){
          if(playOn==0){
          mainMusic.start(0,999);
          playOn=1;
          }
          if(playOn==1){
          mainMusic.stop();
          playOn=0;
          }
          }

          --

          Dan Mode
          --> Adobe Community Expert
          *Flash Helps* http://www.smithmediafusion.com/blog/?cat=11
          *THE online Radio* http://www.tornadostream.com
          *Must Read* http://www.smithmediafusion.com/blog




          "MultiDesign01" <webforumsuser@macromedia.com> wrote in message
          news:efulcn$77j$1@forums.macromedia.com...
          >I am trying to create a music on/off button. I only want one button to do
          >both
          > functions. I added the below ActionScript to the button. The music turns
          > off
          > when the button is pressed, but when pressed again, the music doesn't turn
          > back
          > on. I've created a linkage for the music MP3 (mainMusicID) and defined it
          > in an
          > opening frame using ActionScript, calling it "mainMusic". What am I
          > missing?
          >
          > on (press){
          > if (playing!=true) {
          > mainMusic.start(0,999);
          > playing=true; }
          > mainMusic.stop();
          > playing=false;
          > }
          >


          • 2. Re: toggle music
            MultiDesign01 Level 1
            Ok, maybe I'm misunderstanding where to put this script. First I attached your script to the button instance within a on (press) {} function. The music turned off, but not back on. Then I placed the script in a frame. The music turned off, but not back on. Not sure what is keeping it from turning on again.

            The script used to first define the music instance in a frame is below. This works great when people go back to the main page because the music doesn't start another copy of itself.

            mainMusic=new Sound();
            mainMusic.attachSound("mainMusicID");
            if (playing!=true){
            mainMusic.start(0,999);
            playing=true;}