1 Reply Latest reply on Aug 21, 2009 7:21 AM by Fabien Warniez

    Many buttons each playing there own Audio



          I have been trying to build a simple app with say 20 buttons each one plays it own sound, the text of the button is the name of the MP3  ie. button A plays a.mp3


      this works for one buttoin but i can not work out how to pass in the name of the file to play















      <?xml version="1.0" encoding="utf-8"?>




      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"









      private var soundChannel:SoundChannel;

      // in oredr to stop the sound you need to know the chennel the sound is playing on




      // this function will load and play the sound



      private function playSound():void




      var urlRequest:URLRequest = new URLRequest("jazz.mp3");



      var sound:Sound = new Sound();



      // will stop sound of no device is found



      if(soundChannel != null ) {




      soundChannel = sound.play();





      // this function stops the sound from playing, this need tos work on the sound channel



      private function stopSound():void













      <mx:Button click= "playSound()" label="Play sound" x="305" y="204"




        • 1. Re: Many buttons each playing there own Audio
          Fabien Warniez Level 1



          Try to create a component based on a button, with a SoundChannel, the name of the MP3 as a public String, and on the click event, play the mp3.

          Then in your MXML parent file do:


          <local:MyNoisyButton mp3="jazz.mp3" text="jazz"/>
          <local:MyNoisyButton mp3="house.mp3" text="house"/>
          <local:MyNoisyButton mp3="dance.mp3" text="dance"/>


          Hope this helps.

          1 person found this helpful