3 Replies Latest reply on Jan 30, 2008 8:53 PM by Walter Elias

    Looking for help with multiple sound files in swf file

    Seizer8 Level 1
      Hi all, haven't used the Flash forum much as I havent done a lot of work with Flash. I'm hoping there is an easy action script solution to this problem.

      I have multiple button symbols in my Flash document, each button plays a different song sample. Currently if you click on one song and then another, the two songs play simultaneously.

      I would like it so that if you click on another song sample all other sounds stop, before it plays the selected tune. They could click the stop button, but you know people are out there just clicking and hearing two tunes olay over each other.
      I've done a similar thing where this worked, but the songs were all out there on the timeline and they were only 3 seconds or so, these song samples will be about a minute each when I'm done here, some are way longer right now. Putting these on a timeline seems a bit crazy, so is there a better way to do this?

      Also, if anyone can recommend a good book where this specific issue is addressed that would be awesome!

      Thanks in advance for any help.

      Here is a link to the page in question

      http://www.1800violins.com/song-list.htm

        • 1. Re: Looking for help with multiple sound files in swf file
          ooba Level 1
          Funny that you should post this. I know that I have to address this same issue in the next week or two on a project. I have not had time yet to document anything but my thought is to create a global method that will use a _root var for reference to manage the playing and stoping of an audio file. The method will take in a parameter of value which will be a Sound instance. so for example

          var global_sound:Sound = null;
          audioControl = function( param_sound_ref:Sound ){
          if( global_sound != null ){
          global_sound.stop();
          }

          // set to the new sound file
          global_sound = param_sound_ref;
          global_sound.play();
          }

          Now my syntax could be off as I have not checked any of it but for each frame that you can click to play a new file it would call the method i.e. audioControl( yourSoundInstance ); to play the file.

          If you get this done please post what you have it would help me out also.
          • 2. Re: Looking for help with multiple sound files in swf file
            ooba Level 1
            Also, I tried the link. Granted I only have upto 256k transfer rate but its taking forever to download. Are your audio clips embeded inside of the swf or are you dynamically loading them when requested?
            • 3. Looking for help with multiple sound files in swf file
              Walter Elias Level 2
              One simple thing to try is to add stopAllSounds(); to the button script (this is AS1 and 2, I don't know if it's the same in AS3). So when you click on the button, the script first stops all other sounds, then immediately starts playing the sound associated with the button.

              This is sort of a rough solution, but it'll work. As ooba tries to show, there are more elegant ActionScript solutions, but then you need to dynamically load all sounds.

              For an excellent tutorial about playing sounds in Flash, go to http://kennybellew.com/tutorial/

              It's for AS1, but the principles work just the same.