Frame 1
function xmlIsLoaded(success) {
playList_xml = new XML();
playList_xml = this.firstChild;
if (success) {
i = 0;
while (i < playList_xml.childNodes.length) {
location = String(playList_xml.childNodes[i].attributes.location);
artist = String(playList_xml.childNodes[i].attributes.artist);
album = String(playList_xml.childNodes[i].attributes.album);
songname = String(playList_xml.childNodes[i].attributes.songname);
thisTrack = new mp3Track(location + ".mp3", artist, album, songname);
if (location.length > 0) {
playlist_array.push(thisTrack);
}
i++;
}
clearInterval(trackTimer);
clearInterval(fieldTimer);
if (playlist_array.length > 0) {
playlist_array.shuffle();
playTrack();
} else {
clearInterval(trackTimer);
clearInterval(fieldTimer);
trackInfo = "ERROR: no tracks";
fieldTimer = setInterval(updateFields, 100);
}
} else {
xmlStatus = this.status;
if (xmlStatus < 0) {
xmlStatus = -1 * xmlStatus;
}
errMsg = "There was an error loading the XML:\n";
switch (xmlStatus) {
case 0 :
errMsg = errMsg + "No data returned.";
break;
case 2 :
errMsg = errMsg + "A CDATA section was not properly terminated.";
break;
case 3 :
errMsg = errMsg + "The XML declaration was not properly terminated.";
break;
case 4 :
errMsg = errMsg + "The DOCTYPE declaration was not properly terminated.";
break;
case 5 :
errMsg = errMsg + "A comment was not properly terminated.";
break;
case 6 :
errMsg = errMsg + "An XML element was malformed.";
break;
case 7 :
errMsg = errMsg + "Out of memory.";
break;
case 8 :
errMsg = errMsg + "An attribute value was not properly terminated.";
break;
case 9 :
errMsg = errMsg + "A start-tag was not matched with an end-tag.";
break;
case 10 :
errMsg = errMsg + "An end-tag was encountered without a matching start-tag.";
break;
default :
errMsg = errMsg + "General XML load error.";
}
trackInfo = errMsg;
clearInterval(fieldTimer);
fieldTimer = setInterval(updateFields, 100);
}
}
function updateFields() {
if (trackPlaying) {
trackTotal = track_sound.getBytesTotal();
trackLoaded = track_sound.getBytesLoaded();
trackHead = track_sound.position;
cleanTime = trackHead / 1000;
numMilisec = Math.round(trackHead % 1000);
if (cleanTime < 60) {
numMinutes = 0;
numSeconds = Math.floor(cleanTime);
} else {
numMinutes = Math.floor(cleanTime / 60);
numSeconds = Math.floor(cleanTime % 60);
}
if (numMilisec < 10) {
numMilisec = "00" + String(numMilisec);
} else if (numMilisec < 100) {
numMilisec = "0" + String(numMilisec);
} else {
numMilisec = String(nummiliSec);
}
numMilisec = ((numMilisec < 10) ? ("0" + String(numMilisec)) : (String(numMilisec)));
numMinutes = ((numMinutes < 10) ? ("0" + String(numMinutes)) : (String(numMinutes)));
numSeconds = ((numSeconds < 10) ? ("0" + String(numSeconds)) : (String(numSeconds)));
TrackTime_txt.text = (numMinutes + ":") + numSeconds;
if (trackInfo == "") {
currentChar = 0;
currentSpace = 0;
currentStr = "";
} else if (currentChar < trackInfo.length) {
if (currentChar < tickerMax) {
currentStr = currentStr + trackInfo.charAt(currentChar);
} else {
currentStr = currentStr.substring(1, currentStr.length) + trackInfo.charAt(currentChar);
}
currentChar++;
} else {
if (currentSpace == (tickerMax + trailingSpace)) {
currentChar = 0;
currentSpace = 0;
currentStr = "";
}
if (currentchar < tickerMax) {
currentStr = currentStr + " ";
} else {
currentStr = currentStr.substring(1, currentStr.length) + " ";
}
currentSpace++;
}
} else {
trackInfo = "";
currentStr = "";
currentChar = 0;
currentSpace = 0;
TrackTime_txt.text = "00:00";
clearInterval(fieldTimer);
}
TrackInfo_txt.text = currentStr;
}
function checkTrack() {
if (trackPlaying) {
trackTotal = track_sound.getBytesTotal();
trackLoaded = track_sound.getBytesLoaded();
trackHead = track_sound.position;
if (parseInt(trackLoaded / trackTotal) == 1) {
trackLength = track_sound.duration;
if (trackHead >= (trackLength - 1)) {
nextTrack(1);
}
}
} else {
trackTotal = 0;
trackLoaded = 0;
trackHead = 0;
}
}
function setVol(up) {
if (up) {
currentVol = currentVol + 10;
if (currentVol > 100) {
currentVol = 100;
}
} else {
currentVol = currentVol - 10;
if (currentVol < 0) {
currentVol = 0;
}
}
track_sound.setVolume(_root.currentVol);
}
function playTrack() {
if (!trackPlaying) {
track_sound = new Sound();
track_sound.loadSound(playlist_array[currentTrack].location, 1);
track_sound.setVolume(currentVol);
trackInfo = "";
trackPlaying = 1;
if (playlist_array[currentTrack].artist != "") {
trackInfo = " Artist: " + playlist_array[currentTrack].artist;
} else {
trackInfo = " Artist: N/A ";
}
if (playlist_array[currentTrack].album != "") {
trackInfo = trackInfo + (" Album: " + playlist_array[currentTrack].album);
} else {
trackInfo = trackInfo + " Album: N/A";
}
if (playlist_array[currentTrack].songname != "") {
trackInfo = trackInfo + (" Title: " + playlist_array[currentTrack].songname);
} else {
trackInfo = trackInfo + " Title: N/A ";
}
clearInterval(fieldTimer);
fieldTimer = setInterval(updateFields, 100);
clearInterval(trackTimer);
trackTimer = setInterval(checkTrack, dT);
}
}
function nextTrack(up) {
stopTrack();
if (up) {
currentTrack++;
if (currentTrack >= playlist_array.length) {
currentTrack = 0;
}
} else {
currentTrack--;
if (currentTrack < 0) {
currentTrack = playlist_array.length - 1;
}
}
trackInfo = "";
trackPlaying = 0;
playTrack();
}
function stopTrack() {
track_sound.stop();
trackInfo = "";
trackPlaying = 0;
currentChar = 0;
currentSpace = 0;
trackInfo = "";
currentStr = "";
clearInterval(trackTimer);
}
function mp3Track(location, artist, album, songname) {
this.location = location;
this.artist = artist;
this.album = album;
this.songname = songname;
}
NC_xml = new XML();
NC_xml.ignoreWhite = true;
NC_xml.onLoad = xmlIsLoaded;
Array.prototype.shuffle = function () {
var _local5 = this.length - 1;
var _local3 = _local5;
while (_local3--) {
var _local2 = parseInt(Math.random() * _local5);
var _local4 = this[_local3];
this[_local3] = this[_local2];
this[_local2] = _local4;
}
};
_soundbuftime = 6;
track_sound = new Sound();
playlist_array = new Array();
trackTimer = "";
currentTrack = 0;
currentVol = 100;
trackPlaying = 0;
dT = 50;
tickerMax = 100;
currentChar = 0;
currentSpace = 0;
trailingSpace = 100;
currentStr = "";
fieldTimer = "";
trackInfo = "loading playlist";
NC_xml.load("playlist.xml");
Frame 2
stop();
Symbol 9 Button
on (release) {
stopTrack();
}
Symbol 10 Button
on (release) {
nextTrack(0);
}
Symbol 11 Button
on (release) {
nextTrack(1);
}
Symbol 15 Button
on (release) {
setVol(1);
}
Symbol 16 Button
on (release) {
setVol(0);
}