|
||||||||||||||||
. . . . . |
Creating an xml mp3 player in Flash 8
This is an mp3 player that is driven by an external xml file. <?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. . |
|
||||||||||||||
|
. | Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Forum | Games | free backgrounds | Resume | Flash Animations | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | store | advertisers | . . |
||||||||||||||||