4 Replies Latest reply on Dec 28, 2006 11:05 AM by Newsgroup_User

    ActionScript to turn sound/music off/on

    jmaxon
      What I want to do:

      Use a single Movie Clip to turn sounds/music off and on using Actions. I also want the movie clip to fade up on rollOver and down on rollOut.

      What I have:

      A flash file with a movie clip in the first keyframe. The keyframe has a stop action and the button frame has the following actions:

      var snd = new Sound();
      snd.attachSound("musicsample");

      On the music sample in the Library I added the linkage identifier “musicsample” to export for ActionScript.

      On the button itself I have these Actions:

      on(rollOver) {
      this.gotoAndPlay("btnup");
      }
      on(rollOut) {
      this.gotoAndPlay("btndown");
      }
      on (release) {
      // Toggle a flag between TRUE and FALSE:
      IamActive = not IamActive;
      // Do different things depending on flag's current state:
      if (IamActive) {
      // various actions to be performed for "on" state of button
      _root.snd.start(0, 1);
      else {
      }
      // various actions to be performed for "off" state of button
      _global.Behaviors.Sound.music.stop("music");
      }

      }

      Here is the Flash File I’m working with: http://www.designmx.com/temp/buttonfademusic.fla

      Please help: This might not be the best way, and if there’s a better way please let me know, but if not please help me to figure out why this isn’t working right.

      Thanks for your help!
      - James