Flash MP3 Player

For Project 1 this semester, I did an interactive infographic on the evolution of the iPod.  Having basic knowledge of ActionScript 3.0, I was not fully aware of how to make the 2-D iPod function. Therefore, I watched tutorials on how to play music using buttons. I ended up creating a play and pause button that on the ‘down’ click of the buttons, the song either started or stopped.

Now, after today’s class lesson, I know how to create a Flash mp3 player. This is the basic code to a player that contains play, pause, and seek buttons with dynamic text:

var my_songs:XMLList;
var my_total:Number;

var my_sound:Sound;
var my_channel:SoundChannel;

var current_song:Number = 0;
var song_position:Number;
var song_paused:Boolean;

var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest(“playlist.xml”));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:EVENT):void {

var myXML:XML = new XML(e.target.data);

my_songs = myXML.SONG
my_total = my_songs.length();


myXMLLoader.removeEventListener(Event.COMPLETE, processXML);

myXMLLoader = null;


function playSong(mySong:Number):void {

var myTitle = my_songs[mySong].@TITLE;
var myArtist = my_songs[mySong].@ARTIST;
var myURL = my_songs[mySong].@URL;


title_txt.text = myTitle;
artist_txt.text = myArtist;
if (my_channel) {

my_channel.removeEventListener(Event.SOUND_COMPLETE, onNext);


my_sound = new Sound();
my_sound.load(new URLRequest(myURL));
my_channel = my_sound.play();     my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);


next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:Event):void {
if (current_song>=my_total) {




prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent):void {

if (current_song<0) {
current_song = my_total-1;




pause_btn.addEventListener(MouseEvent.CLICK, onPause);
function onPause(e:MouseEvent):void {

if (my_channel) {

song_position = my_channel.position;




play_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent):void {

if (song_paused) {
my_channel = my_sound.play(song_position);


} else if (!my_channel) {



This code requires you to use a XML document that contains the audio track, the song title and the artist (here is a helpful tutorial). Using this new knowledge, I was able to return to my Project 1 and create an interactive iPod graphic that works similar to an actual iPod.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: