First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: roozbeh afrasiabi(black_death) | Website: http://none
Make your own MP3 player using Flash MX :
Version 2.0


One of the best features of Flash MX is its ability to download mp3 files directly into flash player, before the release of flash MX developers had to import mp3 files into their projects and this made handling such files very hard. But now with the loadSound() function you can easily load mp3s and choose the method flash player downloads them.
There are basically two methods you can use to load your mp3s into flash player:


According to the method you select flash MX gives youdifferent options for handling the file.Event sounds have to be downloaded before they can be controlled, streaming sounds play while they are being loaded, so flash player gives you full control over event sounds and less options for handling streaming sounds.

When you load mp3s as event sounds you can use all commands for handling sound objects that actionscript offers, on the other hand when you load mp3s as streaming sounds you are only given the ability to stop, play or set volume-pan of the music file .

How it is done:

First of all run flash MX and create an empty project. Choose your desired document size and background color.

This mp3 player requires some buttons, you can make your own buttons or Use the buttons flash stores in the common libraries.

We will organize our scripting by using functions for the most part
of the MP3 player.
All functions are placed in the first frame (main scene).



function playa() {
if (playing!=true) {
mysound=new Sound();
if (url!=null) {
mysound.loadSound(url+".mp3", false);
if (mysound.duration!=0) {
} else {

Note: You can not use play as the function name, flash already has
A built in function with that name. In general avoid naming your
Functions with names that are already used by flash.

This function will simply load the mp3 file from the path (URL) you have provided if the URL exists.

Note: you can use an input text box to get the URL from the user.

Note:_root.pos is a variable that stores the file position

If the URL value is null you can use the else command to force the
user into inputting a valid path or file name.


function stopa() {

The _root.pos=0 sets the pos value to zero so if the user calls the
playa function the file will be played from the beginning.


function pause() {
if (playing) {

This function pauses the sound and stores the position value in the
pos variable.(The pos value will be used when the user calls the
playa function, in this way when the music is played again it starts
from the position where it was stopped before)

Copy/paste all these functions to the first frame (on the main scene)
Of your project.


Create an empty movie clip and place the following scripts inside the
first frame of the movie.

if (_root.rw) {
if (_root.playing) {
pose = int((_root.mysound.position)/1000)-1;
_root.mySound.start(pose, 1);

if (_root.fw) {
if (_root.playing) {
pose = int((_root.mysound.position)/1000)+1;
_root.mySound.start(pose, 1);

Now select the next frame and convert it to a keyframe this will make a loop.


Create a global sound object that can control the overall sound volume:

globalvolume = new Sound();

Place the above script in the first frame(main scene) we will use a button to
control this object.


Just use the buttons you made before to call these functions .


on (press) {


Copy/paste the following scripts to the buttons you have made


on (press) {
fw = 1;
on (release, releaseOutside, rollOut, dragOut) {
fw = 0;


on (press) {
rw = 1;
on (release, releaseOutside, rollOut, dragOut) {
rw = 0;


on (release) {
if (_root.globalvolume.getVolume()>0) {
} else {



Add these to the first frame(main scene) of your movie:

var pos=0;

These will set the default values for playing and pos.


you can use any fader to control the volume-pan of your mp3.

Note: If you can not handle making a fader use the faders in the common
libraries of flash MX.

And that’s it you have made your own MP3 player and it works fine.
You can now use your knowledge of action script to make this player as
complicated or as simple as you want.

» Level Advanced

Added: 2002-12-12
Rating: 5.93 Votes: 154
(10 being the highest)
» Author
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.