flash animation video tutorials

 

 

 

 

 

START LEARNING
FLASH NOW

Get instant access to over
45 minutes of FREE Flash tutorials on video
 and our newsletter.

Name:
E-Mail:

.

.

.

 
Web video-animation.com

.

.

flash tutorials flash tutorials flash tutorials flash tutorials

Creating an xml mp3 player in Flash 8

This is an mp3 player that is driven by an external xml file.
This tutorial is taken from the brilliant work by Lee Brimelow at www.gotoandlearn.com
So the first step is to create an xml file that contains your song playlist of your mp3 files.
Let us call it songs.xml
Create and edit it using a text editor such as notepad or Crimson Editor or Textpad. Make sure that you put your xml file into the same folder as your flash file and your mp3 files. So all files go into one folder for this project.

 

<?xml version="1.0" encoding="UTF-8" ?>
<beats>
<beat url="test01.mp3"/>
<beat url="test02.mp3"/>
<beat url="test03.mp3"/>
<beat url="test04.mp3"/>
</beats>

Flash Tutorials in Video Format - Watch them now at LearnFlash.com  

The only attribute that each beat has in the xml structure or node is the url. The Artist name and song name will be embedded in the mp3 id tags. We will see how to do that in a later tutorial.

Now create a flash 8 file and go to the first layer and rename it actions and on the first frame of the actions layer put the code in it.


// create a Sound object 
var mySound:Sound = new Sound();
// when a song is finished call playbeat function
mySound.onSoundComplete = playbeat;
// set initial volume to 75%
mySound.setVolume(75);

// create array of all beats.. 
var beatArray:Array = new Array();
// counter to current beat. 
var nowBeat:Number = -1;
// create xml object 
var xml:XML = new XML();
xml.ignoreWhite = true;
// load xml
xml.onLoad = function(){
	var nodes:Array = this.firstChild.childNodes;
	// iterate through array - push into beatArray
	for(var i=0;i<nodes.length;i++){
	beatArray.push(nodes[i].attributes.url);	
	}	
	playbeat();
}

// tell it to load in xml file
xml.load("songs.xml");
// play beats
function playbeat(){
// check which song is playing
// if at end, play first one 
if(	nowBeat == beatArray.length-1){
	nowBeat = 0;
	mySound.loadSound(beatArray[nowBeat], true);
}
else {
mySound.loadSound(beatArray[++nowBeat], true);	
}

}

Now test it, it should be play away merrily without any interface or control whatsoever. Next tutorial we will hand control back to the punters and give them a bit of an interface but we do not want to spoil them, do we?

Flash 8 Resources

An extended mp3 player with listbox giving aritiste etc, and a play and pause button.

Tree Component and XML playlist

.

flash 8