4 Replies Latest reply on Mar 23, 2010 7:38 AM by Francisc

    Play multiple sounds

    Francisc Level 3

      Hello!

       

      How can I play multiple sounds at once please?

      I tried with 2 separate soundChannel vars but they still override eachother.

       

      Thanks

        • 1. Re: Play multiple sounds
          Matt Le Fevre Level 4

          play both sounds through the same sound channel? eg:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
              
              <mx:Script>
                  <![CDATA[
                      private var sound:Sound;                        
                      private var soundChannel:SoundChannel;    
                      
                      
                      private function play1():void
                      {
                          
                          sound = new Sound();
                          sound.load(new URLRequest("sounds/1.mp3"));
          
                          sound.addEventListener(Event.COMPLETE, songLoaded);
                      }
                      
                      private function play2():void
                      {
                          
                          sound = new Sound();
                          sound.load(new URLRequest("sounds/2.mp3"));
                      
                          sound.addEventListener(Event.COMPLETE, songLoaded);
                      }
                      
                      private function songLoaded(e:Event):void 
                      {
                          try
                          {
                              sound.removeEventListener(Event.COMPLETE, songLoaded);    
                              soundChannel = sound.play(0);
                          }
                          catch(err:Error)
                          {
                              trace(err)
                          }
                      }
                      
                      
                  ]]>
              </mx:Script>
          
              <mx:Button x="140" y="313" label="Play sound 1" click="play1()"/>
              <mx:Button x="229" y="326" label="Play sound 2" click="play2()"/>
          </mx:Application>
          
          
          • 2. Re: Play multiple sounds
            Francisc Level 3

            I did initially, but it seemed to override the first sound.

             

            I'll give it another go later today and comeback with the `verdict`.

             

            Thanks!

            • 3. Re: Play multiple sounds
              Matt Le Fevre Level 4

              well i just had a "lovely" mix of jamiroquai and cheryl cole playing at the same time, so i'd suggest chosing better sounds to mix than that!

              • 4. Re: Play multiple sounds
                Francisc Level 3

                Correctomundo!

                Thank you!