What actionscript do I need to add to have a user click on a button symbol to play a 30 second music clip (mp3 file) in Flash MX 2004?
Click a Button Symbol to play an .mp3 clip
Collapse
X
-
-
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_b tn"
And here are details for this scriptCode: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); }
SoundLoaderCont ext(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 luckComment
Comment