8 Replies Latest reply on Apr 25, 2008 2:16 PM by FlashTastic

    Audio Scripting Question

    witt2008
      I am working in Action Script 2 on a Project that can be found here... Panning Image I posted my question in the Action Script 3 forum by accident. Basically what I am trying to do is have multiple hotspots where you can click and hear audio clips. I have no problem creating these invisible hotspots as I have done one already if you click on the notebook. My problem however, is with the audio overlap if you click the hotspot more than once, or click another hotspot. I am relatively new to flash, and in the other forum someone suggested that I do the following:

      quote:

      Originally posted by: Gaunt Face
      My approach to fix it would be this :

      Just create a boolean variable that indicates whether a noise is playing. Then before your actionscript plays a noise, make it check the boolean value, if its true you need to stop any other noise and then play the new noise, if it is false then just let it play the noise.

      But you must make sure you add action listeners for when the noise is finished to set the boolean to false and ensure that just before a noise is played the boolean is set true.

      Hope that helps a bit

      Gaunt



      Does anyone have any suggestions as to exactly how this would be coded? I am relatively new to coding in Flash Actionscript 2.0 and any suggestions would be greatly appreciated.
      Thanks
      Ryan
        • 1. Re: Audio Scripting Question
          robdillon Most Valuable Participant
          To play a sound, you might have something like this:
          var my_sound:Sound = new Sound();
          my_sound.attachSound("soundName");
          my_sound.start();

          To safeguard that the sound plays only once, you might do something like this:

          var sound1Playing:Boolean = false;

          soundButton.onRelease = function() {
          var my_sound:Sound = new Sound();
          my_sound.attachSound("logoff_id");
          my_sound.onSoundComplete = callback1;
          my_sound.start();
          sound1Playing = true;
          }
          function callback1() {
          sound1Playing = false;
          }
          • 2. Re: Audio Scripting Question
            robdillon Most Valuable Participant
            To play a sound, you might have something like this:
            var my_sound:Sound = new Sound();
            my_sound.attachSound("soundName");
            my_sound.start();

            To safeguard that the sound plays only once, you might do something like this:

            var sound1Playing:Boolean = false;

            soundButton.onRelease = function() {
            if(!sound1Playing) {
            var my_sound:Sound = new Sound();
            my_sound.attachSound("logoff_id");
            my_sound.onSoundComplete = callback1;
            my_sound.start();
            sound1Playing = true;
            }
            }

            function callback1() {
            sound1Playing = false;
            }
            • 3. Re: Audio Scripting Question
              witt2008 Level 1
              Thanks for the information.... I am still having problems however, Here is a weblink to the raw fla file I am working with in Flash. It is a relatively large file, but it will load. It has 2 hotspots. However, when I go and try to load the actionscripting, I am having trouble finding exactly where to insert the code. If I go into the buttons and load the actionscript there, is nothing there.... I am just unsure where exactly to insert this code as I cannot find where the code is currently at that is making this audio play. Any help would be appreciated.
              Thanks
              Ryan
              Fla Link to download
              • 4. Re: Audio Scripting Question
                robdillon Most Valuable Participant
                Here's the edited file: http://www.ddg-designs.com/downloads/test4.zip

                Look in the layer titled Actions for a list of the changes that I made. You should be able to follow this structure.
                • 5. Re: Audio Scripting Question
                  witt2008 Level 1
                  Thanks that looks great... I have one other question, what would I do if I wanted to have a audio segment play at the beginning of the image, and have the same thing apply where if a button is clicked it would stop? What would the coding for that be?
                  Thanks
                  Ryan
                  • 6. Re: Audio Scripting Question
                    witt2008 Level 1
                    Anyone that could help with one final question? What code do I insert in the actionscript for a sound that I only want to play once at loading of the image?
                    Thanks
                    Ryan
                    • 7. Re: Audio Scripting Question
                      witt2008 Level 1
                      bump
                      • 8. Re: Audio Scripting Question
                        FlashTastic Level 1
                        What you could do it call stopAllSounds(); right before initializing your audio
                        (on any clip). It's a much easier solution than what has been proposed in this thread.

                        For example, anywhere where you code in a sound to play use:

                        stopAllSounds()
                        var my_sound:Sound = new Sound();
                        my_sound.attachSound("soundName");
                        my_sound.start();

                        This ensures that all sounds are stopped before the new sound is played.

                        Cheers,
                        FlashTastic