Flash MP3 Player Tutorial
//Declarations global variables filenametext=""; var s:Sound = new Sound(); var songsXml:XML = new XML(); var nodes:Array = new Array(); var cps:Number=-1;//so that incrementing in playsong starts with cps at 0. songsXml.ignoreWhite = true; songsXml.load("songs.xml"); songsXml.onLoad = loadSongs; function loadSongs(success) { if(success) { //enter first song filename in the textfield nodes = songsXml.firstChild.childNodes; } else { //enter failed to load songs.xml in textfield filenametext = "songs.xml could not be loaded."; } } play.onRelease=function() { playsong(); s.setVolume(75); s.onSoundComplete = playsong; } function playsong() { if(cps<nodes.length-1) { s.loadSound(nodes[++cps].firstChild.nextSibling.firstChild,true); filenametext = nodes[cps].firstChild.nextSibling; } else { cps=-1; s.loadSound(nodes[++cps].firstChild.nextSibling.firstChild,true); filenametext = nodes[cps].firstChild.nextSibling; } } next.onRelease=function() { //cps++; stopAllSounds(); playsong(); } previous.onRelease=function() { if(cps==0) { cps=nodes.length-2; } else { cps=cps-2; } stopAllSounds(); playsong(); }
