[Kernel32 the underground army ]
This document was released by : Black_Death
It was approved by Kernel32 X3 member cyber_b_u_g
members can download the source from:
2032 5378 991 6771 3526 2337 9406 7636 6463 5729 8825 4740 6771 8765 1892
4970 3178 798 855 8731 3124 8652

Skill level:Advanced

Make your own MP3 player (flash):


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 basicly two methods you can use to load your mp3 based music or
sound files into flash player:


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

When you load mp3s as event sounds you can use all commands for handeling
sound objets 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 file.

In this document we will not cover streaming sounds because if you learn
how to handle event sounds you can control streaming sounds too.

How to:

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

Start from one layer and one frame for the movie.Our mp3 player requies
some buttons,you can make your own buttons or use the buttons flash stores
in the common libraries .

We will orgnize our scripting by using fuctions for the most part
of the MP3 player.
All functions are placed in the first frame.



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

As you might have noticed I have named the function playa,that is to
avoid any illegal nomenclauture of functions.

This fuction will simply load the mp3 file from the path(url)you have
provided if that url is not empty.

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

_root.pos is a value that tells the start function to start playing the
file from a desired position.(you will soon learn this works)

If the url value is empty you can use the else command to force the
user into inputing 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 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,this will force the file to start from the position
where it was paused)


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


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

These two functions change the position of the file by stopping it
first and then playing it from a different position.

Copy past these functions to the first frame of your project.


Now for the easy part,use the buttons you made before to call these


Add these to the first frame 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.

And thats it you have made your own MP3 player and it works fine.
You can now use your knowledge of flash to make this player as
complicated or as simple as you want.

Note:There are more commands for controling mp3 files that i have
not said a word about.

For those who want to make more complicated MP3 players:

Try answering these questions:

1.How can I mute the sound?
2.How can I check for availability of mp3 decoders?
3.How can I check if the path or file name exists or not?
4.How can I make a bar that shows the file position?

by:Black Death Kernel32 web development unit