The following examples show how you can dynamically load MP3 files into your SWF using the Sound class in ActionScript 2.0 and ActionScript 3.0.
Full code after the jump.
The following example shows how you can load an external MP3 file using the Sound class and loadSound() method in ActionScript 2.0:
// ActionScript 2.0 var url:String = "http://www.helpexamples.com/flash/sound/song2.mp3"; var sound:Sound = new Sound(); sound.loadSound(url, true);
The following example shows how you can load an external MP3 file using the Sound class and the load() and play() methods in ActionScript 3.0:
// ActionScript 3.0 var url:String = "http://www.helpexamples.com/flash/sound/song2.mp3"; var urlRequest:URLRequest = new URLRequest(url); var sound:Sound = new Sound(); sound.load(urlRequest); sound.play();
Obviously, these are very simplified examples of loading MP3s. In later examples we’ll explore things like ID3 information and setting the volume on the sounds.
{ 3 comments… read them below or add one }
I have tried the actionscript 2.0 example the standalone swf plays the mp3. But whenever i tried the swf on web server inside an html, it doesn’t play the mp3.
Great! I thought AS 3.0 was for geeks and goons! But its working, and Im neither. So Im happy!
Thanks a lot mate!
Roshan!
works fine for me, quick & easy, thanks.