Here is the code you need for AS3 to be able to play a mp3 file when a button is clicked
Lets say we have a button on the stage called "myButton_btn"
-
myButton_btn.addEventListener(MouseEvent.CLICK, buttonIsClicked);
-
-
function buttonIsClicked(event:Event):void
-
{
-
var sndcontext:SoundLoaderContext = new SoundLoaderContext(4000);
-
var snd:Sound = new Sound(new URLRequest("http://www.yourdomain.com/yoursound.mp3"), sndcontext);
-
var sndchannel:SoundChannel = snd.play(0,1000);
-
sndchannel.soundTransform = new SoundTransform(0.2, 1);
-
}
-
And here are details for this script
SoundLoaderContext(4000) is the limit of your buffer. This means that your sound must be buffered at least 4000 milliseconds (4 seconds) to be played.
snd.play(0,1000) shows how many times your music should be played
SoundTransform(0.2, 1) the fist number shows the volume of your sound and the second one shows the balance on your speakers . Between -1 and 1 for left and right balance on your speakers
Hope it helps
Good luck