Flash Audio: Streaming MP3’s in Flash

This tutorial will shortly explain the importance of the loadSound method. This method is used when you want to load external MP3 files. Here is the syntax:
public loadSound(url:String, isStreaming:Boolean) : Void
Let’s see how it works!
As I already said, this loads an MP3 file into the Sound object you created. The parametar isStreaming is interesting. You can use it to indicate whether the sound is an event or a streaming sound.
Just like it is the case with every sound, event sounds must be completely loaded before they play. They are managed by the ActionScript Sound class and respond to all methods and properties of this class.
Streaming sounds play while they are downloading. Playback begins when sufficient data has been received to start the decompressor.
All MP3s (event or streaming) loaded with this method are saved in the browser’s file cache on the user’s system. Here is the overview of the two parameteres:
url:String – The location on a server of an MP3 sound file.
isStreaming:Boolean – A Boolean value that indicates whether the sound is a streaming sound (true) or an event sound (false).
Let’s create an example!
Open up a new Flash document. Place an input text field onto the stage (Image 1).
Streamign Audio on Flash

Give it an instance name songName_txt (Image 2).

Streaming MP3 audio in Flash

Add a simple button besides the text field and give it the instance name startSound_btn.(Image 3)

Load sound flash tutorial

Ok, now add an additional layer and name it „Actions“. Rename the layer with the text field at the botton to „Text Field“ (Image 4).

Make sure you have MP3 tracks in the same folder where the Flash movie resides.
Select the first frame of the layer Actions and add the following ActionScript:
var soundToLoad:Sound = new Sound();
startSound_btn.onRelease = function () {
    var song = songName_txt.text;
    soundToLoad.loadSound(song, true);
soundToLoad.onLoad = function () {
    this.start(0, 1);
Test the movie. Type in the name of one of your tracks and press the start button. The mp3 file should load and play!

About admin

My name is Mark Lewis. I own a few popular royalty free content websites. I have been helping musicians distribute their music for over 17 years now and wanted to use this forum to share thoughts and experiences and hopefully spark some discussion in regards to the distribution of royalty free music and royalty free content in general.