2 Replies Latest reply on Apr 28, 2011 5:24 AM by Captain825

    Sound control actionscript 2

    Captain825 Level 1

      Flash 8 site, AS2.

       

      Site has background music that it loads externally through the following code in frame 1 of the root timeline.

       

      var b:Sound=new Sound(); 

      stopAllSounds();

      b.attachSound("cool");
      b.start();

       

      The idea is that when the user clicks on a menu choice, the site branches to another movie clip representing the page the user selected.  Once the selected page opens, the background music of the site should pause and the selected page's music should start.  When the user exits the selected page, the selected page's music should stop and the background music should resume where it left off.

       

      The code that I have on the first frame of the selected page's timeline is:

       

      pauseTime = b_sound.position;

      b_sound.stop(  );

       

      var l:Sound=new Sound();

      l.attachSound("still");
      l.start();

       

      The background music stops when the selected page opens and the selected page's music starts fine, but the background music doesn't resume when the user exits the selected page.

       

      I put a Trace on pauseTime and I get "undefined".

       

      Any help would be greatly appreciated.

       

      Adrian

        • 1. Re: Sound control actionscript 2
          adninjastrator Level 4

          Maybe you can adapt this "pause" method and work it into your project:

           

          //-------MUSIC PLAYER CONTROLS--------//
          var currentPosition:Number = 0;
          var paused:Boolean = false;

          stop_btn.onRelease = function() {
          currentPosition = 0;
          jukebox.stop();
          paused = true;
          disk_mc.stop();
          indLights();
          }

          play_btn.onRelease = function() {
          if (paused) {
            jukebox.start(currentPosition);
            paused = false;
            disk_mc.play();
            indLights();
          }

          }

          pause_btn.onRelease = function() {
          if (!paused) {
            currentPosition = jukebox.position/1000;
            jukebox.stop();
            paused = true;
            disk_mc.stop();
           
          }
          else
          {
            if (currentPosition > 0) {
             jukebox.start(currentPosition);
             paused = false;
             disk_mc.play();
            }
          }
          }

          mute_btn.onRelease = function() {
          if (jukebox.getVolume() > 0) {
            jukebox.setVolume(0);
          }
          else
          {
            jukebox.setVolume(100);
          }
          }

           

          ignore the stuff about the disk_mc and indLights .... the pause button also does other stuff... see it in action here:

          http://www.uncledoodad.com/02_05_11/02_05_11.html

           

          Best wishes,

          Adninjastrator

          • 2. Re: Sound control actionscript 2
            Captain825 Level 1

            Thank you.  Just what I needed!  I am sure I can tweak this code to fix my problem.