You have a lot of mp3 music and you want to burn them to a CD. You can add a music player to the CD for play them in other computers. Now, you can create the music player by using Flash components with ActionScript 2.0. This article will show you how to create a music player with ActionScript.
Solution
- Open Adobe Flash CS4.
- Create a new Flash file with ActionScript 2.0 and then save the file as “music player.fla”.
- Right-click the work area and select Document Properties to open Document Properties window. Then input 300 px as width and 70 px as height.
set background size - Select Window on the menu bar and choose Components to open COMPONENTS window.
open COMPONENTS window

- Drag the MediaController component and the MediaDisplay component to LIBRARY window from COMPONENTS window.
drag component to library - Input the following codes in the “Actions” of the first frame.
function init(){
flagNum = 1;
mp3Num = 0;
attachController();
};
function attachController(){
_root.attachMovie(“MediaDisplay”,”mp3Container” + flagNum,2);
with(_root["mp3Container" + flagNum]){
_x = 250;
_y = 0;
setMedia(myArray[mp3Num],”MP3″);
}
_root.attachMovie(“MediaController”,”mp3Controller” + flagNum,1);
with(_root["mp3Controller" + flagNum]){
_x = 0;
_y = 0;
activePlayControl = false;
controllerPolicy = “on”;
associateDisplay(_root["mp3Container" + flagNum]);
};
};
function playNext(){
_root["mp3Controller" + flagNum].removeMovieClip();
_root["mp3Container" + flagNum].removeMovieClip();
flagNum += 1;
mp3Num += 1;
if(mp3Num == mp3Total) mp3Num = 0;
attachController();
_root["mp3Container" + flagNum].addEventListener(“complete”, myListener);
}; - Insert a new layer and then input the following codes in the “Actions” of the first frame.
stop();
var myArray = new Array();
var mp3Total:Number;
var myXml = new XML();
myXml.ignoreWhite = true;
myXml.load(“mp3list.xml”);
myXml.onLoad = function() {
var e = myXml.firstChild.childNodes;
mp3Total = e.length;
for (var i = 0; i<mp3Total; i++) {
myArray.push(e[i].attributes["title"]);
}
init();
_root["mp3Container"+flagNum].addEventListener(“complete”, myListener);
};
var myListener = new Object();
myListener.complete = function(eventObject) {
playNext();
}; - Create a new xml named “mylist.xml” like this.
<?xml version=”1.0″ encoding=”utf-8″?>
<mp3Lists>
<item title=”1.mp3″ />
<item title=”2.mp3″ />
</mp3Lists> - Press Ctrl+Enter to output the “.swf” file named “music player.swf”.
output music player.swf - Put the “1.mp3″, “2.mp3″, “music player.swf”, “mylist.xml” in a same folder.
put all files in a same folder - Now, we have finished creating a music player with ActionScript. You can enjoy your Flash music player.




October 21, 2010 at 3:50 pm
This tutorial does not work properly. It does not describe adding the components to the layers and I get errors in the actionscript in the following locations,
myXml.load(“mylist.xml”);
_root["mp3Container"+flagNum].addEventListener(“complete”, myListener);
};
Please advise how to fix these error messages. Thanks!
October 21, 2010 at 3:56 pm
Nevermind. I found the problem. Thanks!
November 25, 2010 at 12:01 pm
Dear sir/madam
Thank you so much & plz sede flv file with Action Script As3 to mail id
Thank you
January 7, 2011 at 10:42 pm
How come my site comes up as undefined when i publish the video.
all works except for the audio playing.
please advise.
thanks
January 10, 2011 at 1:09 pm
i’m following your guide, but i’m totals rubbish with flash, i’ve got as far as the create xml file, but i don’t know how too
April 18, 2011 at 9:37 pm
I did everything you advised in tutorial but I get this error message. I do not know where I went wrong. All the files are in one folder.
Error message received in flash.
Error opening URL ‘file:///C|/Graphic%20Software/newlife/music/undefined’