i am making a simple mp3 player using a list component. ive tried everything to do what im trying to do: im trying to make it so that when i load a new song all of the variables for the last song are reset. that tasks seems impossible. ive tried EVERYTHING, or that is what i think. any help would be greatly appreciated :D. below is my AS code. i would upload my file, but its too big. link to file
var artistList:mx.controls.List;
var sound:Sound = new Sound();
info_txt.autoSize = true;
import mx.styles.CSSStyleDeclaration;
var new_style:Object = new CSSStyleDeclaration();
new_style.setStyle("fontFamily", "_sans");
new_style.setStyle("fontSize", 10);
new_style.setStyle("fontWeight", "normal");
new_style.setStyle("textDecoration", "none");
new_style.setStyle("color", 0xffffff);
new_style.setStyle("borderStyle", "solid");
new_style.setStyle("borderColor", "0x666666");
new_style.setStyle("backgroundColor", "0x000000");
new_style.setStyle("selectionDuration", 0);
new_style.setStyle("textRollOverColor", "0xff3399");
new_style.setStyle("textSelectedColor", "0x666666");
new_style.setStyle("themeColor", "0x111111");
_global.styles.myStyle = new_style;
artistList.setStyle("styleName", "myStyle");
songList.setStyle("styleName","myStyle");
var artistXML:XML = new XML();
var artists:Array = new Array();
var xmlSource = "playlist.xml";
artistXML.ignoreWhite = true;
artistXML.load(xmlSource);
artistXML.onLoad = function(success) {
if (success) {
artistNode = artistXML.firstChild.childNodes;
for (i=0; i<artistNode.length; i++) {
artistList.addItem(artistNode*.attributes.name);
}
}
artistIndex = -1;
updatesongList(artistIndex);
};
var listener:Object = new Object();
listener.change = function(e:Object) {
if (e.target._name == "artistList") {
songList.removeAll();
artistIndex = e.target.selectedIndex;
updatesongList(artistIndex);
} else if (e.target._name == "songList") {
sound.stop();
songIndex = e.target.selectedIndex;
prepare(songIndex, artistIndex);
}
};
artistList.addEventListener("change", listener);
songList.addEventListener("change", listener);
updatesongList = function (artistIndex) {
songsNode = artistNode[artistIndex].childNodes;
for (i=0; i<songsNode.length; i++) {
songList.addItem({label:songsNode*.attributes.name, data:songsNode*.attributes.url});
}
};
prepare = function (songIndex, artistIndex) {
clearInterval(clock)
info_txt.text = artistNode[artistIndex].attributes.name+" - "+songsNode[songIndex].attributes.name
sound.loadSound(songsNode[songIndex].attributes.url, true);
clock = setInterval(timeInfo, 75);
};
sound.onLoad = function(){
songLength = this.duration
}
timeInfo = function(){
var totalSeconds:Number = sound.position/1000;
var percentPlayed:Number = sound.position / songLength;
var minutes:Number = Math.floor(totalSeconds/60);
var seconds = Math.floor(totalSeconds)%60;
if (seconds<10) {
seconds = "0"+seconds;
}
positionbar_mc._width = percentPlayed * 300;
timeinfo_txt.text = minutes + ":" + seconds;
}