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.
9 Responses to Loading external MP3 files in ActionScript 2.0 and ActionScript 3.0
Leave a Reply Cancel reply
Recent Posts
- Getting started with the TLFTextField class in ActionScript 3.0 and Flash CS5
- Adding tick marks to a Slider control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Creating a custom context menu item in Flash using ActionScript 3.0
- Rotating a Sprite object around its x-axis in Flash using ActionScript 3.0 and Flash Player 10
- Detecting when the user changes the color in a ColorPicker control in Flash using ActionScript 3.0
- Getting the currently selected color as a hexadecimal value on a ColorPicker control in Flash using ActionScript 3.0
- Toggling the text field on the ColorPicker control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Setting the number of columns on a ColorPicker control in Flash using ActionScript 3.0
Categories
- Bitmap (1)
- Components (72)
- Button (19)
- CheckBox (2)
- ColorPicker (6)
- ComboBox (1)
- DataGrid (8)
- FLVPlayback (7)
- Label (9)
- ProgressBar (2)
- Slider (3)
- TextArea (1)
- TextInput (7)
- UILoader (7)
- ContextMenu (1)
- Embed (4)
- ExternalInterface (2)
- Flex (7)
- Font (2)
- General (5)
- Graphics (2)
- JSFL (14)
- Loader (3)
- LoadVars (3)
- Microphone (1)
- migration (12)
- MovieClip (1)
- MovieClipLoader (1)
- Sound (2)
- TextField (1)
- TLFTextField (1)
- TransitionManager (1)
- Tween (1)
- Uncategorized (1)
- URLLoader (4)
- URLVariables (1)
- Video (1)
- XML (2)
Advertising
" RT @OReillyMedia: #Ebook Deal/Day: Learning JavaScript Design Patterns -
$11.99
(Save 50%)
http://t.co/ilcmSDv6 " — pdehaan


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.
i tried this,,working good
How would I put a loop function into the actionscript itself?
I’ve tried looping using Adobe Flash CS4, but for some reason it just won’t loop.
Also, I forgot to mention, I’m using Actionscript 3.0
Hello.Please try to solve my problem
//Action//
var url:String = “http://sound.nasr19.ir/uploads/1319552123.mp3″;
var S:Sound = new Sound();
S.loadSound(url, true);
//in this part the sound does not repeat. What is the problem?//
s.onSoundComplete = function ()
{s.start (0,999)};
timerinProgress = false;
musicOn = true;
playing = true;
newPosition = 0;
onEnterFrame = function () {
if (advance) {
if (s.position/1000+1<s.duration/1000) {
if (playing) {
newPosition = s.position/1000+1;
s.stop();
s.start(newPosition, 1);
}}};
if(s.getBytesLoaded() == s.getBytesTotal()){
trace("the sound is loaded")
} else {
trace("the sound is not loaded")}};
//in this part of cod the Button Does not work (can not play && pause). What is the problem?//
//Button cod//
on (release) {
if (!_root.playing && _root.newPosition < _root.s.duration) {
_root.s.start (_root.newPosition, 1);
_root.playing = true;
} else if (_root.playing) {
_root.newPosition = _root.s.position / 1000;
_root.s.stop ();
_root.playing = false;
}}
the sound load But Button Does not control && play and pause the sound
help mi! Thanks and waiting .As2
works fine for me too, swf and swf in html
[flash cs5, AS2]
thanks! :)
Nice. Short and practical explanation. Thank you!