5 Replies Latest reply on Sep 21, 2010 8:28 AM by kglad

    When I stop a sound object, my video sound stops, too.

    kalibahlu Level 1

      I hope someone can offer some advice. I have a flash file with a background music sound object, and I have a video player at a particular section on the timeline. When the playback head goes to the section with the video player, I would like the background music to fade, but of course, I need the volume to be up for the video. The code I have works find to fade the audio, but the problem is that the video's sound also turns off. Could someone please take a look at my code, and let me know what I'm doing wrong?

      This is the code at the beginning of the timeline:

       


      _global.volumeVar = 40;  //Stores the current volume.

       

      bgSound = new Sound(this);                    //This block works fine
      bgSound.attachSound("music");
      bgSound.start(0,99);

      bgSound.setVolume(0);

       

      var nInterval:Number = setInterval(fadeInSound, _global.volumeVar);    //fades in music -works fine

       

      function fadeInSound():Void {                                  //this function works fine
          if (bgSound.getVolume()<_global.volumeVar && _global.off0n == 1) {
              bgSound.setVolume(_root.bgSound.getVolume()+2);
          } else {
              clearInterval(nInterval);
          }
      }

       

      function fadeOutSound():Void {                 //gets called further down the timeline
          if (bgSound.getVolume()>0) {
              bgSound.setVolume(_root.bgSound.getVolume()-5);
          } else {     
              bgSound.setVolume(0);
              _root.setVolume(100);          //hoped this would turn on the video sound, but it didn't
              clearInterval(nInterval);
          }

       

      Further down the time line, in the video player section, there this code, which works to fade the sound, but seems to turn off the video, too:

       

      nInterval = setInterval(fadeOutSound, _global.volumeVar);

       


      Thank you for looking. I've been researching and working on this problem all day, and can't seem to find the answer. Seems easy, conceptually, but I just can't get the sound object and video audio to stay separate. They're either both on or both off. Does anyone have experience with this that they could share? Thank you very much!

        • 1. Re: When I stop a sound object, my video sound stops, too.
          kglad Adobe Community Professional & MVP

          try:

           


           


          _global.volumeVar = 40;

           

          var mc:MovieClip=this.createEmptyMovieClip("mc",this.getNextHighestDepth());

          bgSound = new Sound(mc);                    //This block works fine
          bgSound.attachSound("music");
          bgSound.start(0,99);

          bgSound.setVolume(0);

           

          var nInterval:Number = setInterval(fadeInSound, 70);    //fades in music -works fine

           

          function fadeInSound():Void {                                  //this function works fine
              if (bgSound.getVolume()<_global.volumeVar && _global.off0n == 1) {
                  bgSound.setVolume(_root.bgSound.getVolume()+2);
              } else {
                  clearInterval(nInterval);
              }
          }

           

          function fadeOutSound():Void {                 //gets called further down the timeline
              if (bgSound.getVolume()>0) {
                  bgSound.setVolume(_root.bgSound.getVolume()-5);
              } else {     
                  bgSound.setVolume(0);
                  clearInterval(nInterval);
              }

           

           

          Further down the time line, in the video player section, there this code, which works to fade the sound, but seems to turn off the video, too:

           

          nInterval = setInterval(fadeOutSound, 70);

           

           

          • 2. Re: When I stop a sound object, my video sound stops, too.
            kalibahlu Level 1

            kglad, thank you thank you thank you!!! That was it! You are truly amazing and once again have relieved my suffering! I tried all day, and I don't think I ever would have figured it out, as with all my research, putting it in an mc didn't come up.  With all that I've read, I'm still having a hard time grasping the purpose of the second parameter in the setInterval statement (in this case, 70). Is there way you can explain the meaning of that to a dummy?

            • 3. Re: When I stop a sound object, my video sound stops, too.
              kglad Adobe Community Professional & MVP

              you can independently control, at most, one sound per timeline/movieclip.  if you there are two sounds relative to one movieclip and you do something (like adjust volume) to one of the sounds, you will do the same to the other sound.

               

              to resolve, use a movieclip unique to each sound.  so, if you had 10 sounds you wanted to control, create 10 movieclips and use them in the sound constructor like i did above.

               

              p.s.  please mark this thread as answered, if you can.

              1 person found this helpful
              • 4. Re: When I stop a sound object, my video sound stops, too.
                kalibahlu Level 1

                Thank you for your explanation, I appreciate your help. I was just waiting to mark as answered, just in case it would close the thread if I did, but I'll do that now. Thanks again, kglad!  You rock   have a great day!