The problem I am having is that when the selectedItem is clicked on it displays an error and keeps playing the current song. What do I need to do in order to get it to play the selectedItem
I have included the codfe here as you can see as well as uploaded the file to look at. I could use any help on cleaning it up as well as criticism on it as it's my first flash project. I am also trying to figure out how i call the initbars function so it only plays if music is and stops when it does.
Thanks
stop();
title_txt.autoSize = "left";
timeDisplay_txt.autoSize = "left";
toolTip._visible = false;
var amountLoaded:Number;
var duration:Number;
//Open XML and put data into array
var playlist:XML = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
_global.songname = [];
_global.songband = [];
_global.songfile = [];
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
mp3List.addItem(songband[i]+" ("+songname[i]+")");
}
}
//Start and load movieclip
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = 0;
_root.sound_mc.songStarter(songfile[song_nr]);
// ListBox component commands
mp3List.selectedIndex = 0;
mp3List.hScrollPolicy = "on";
mp3List.maxHPosition = 150;
mp3list.selectable = true;
// Change playing song when tracks are clicked
var mp3Change:Object = new Object();
mp3Change.change = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
};
mp3list.addEventListener("change", mp3Change);
};
//Timer Function
function timer(sound_obj) {
time = sound_obj.position/1000;
min = Math.floor(time/60);
min = (min<10) ? "0"+min : min;
sec = Math.floor(time%60);
sec = (sec<10) ? "0"+sec : sec;
timeDisplay_txt.text = min+":"+sec+"/"+totalDuration;
}
//For time left playing
function duration (){
timed = _root.sound_mc.sound_obj.duration/1000;
mind = Math.floor(timed/60);
mind = (mind<10) ? "0"+mind : mind;
secd = Math.floor(timed%60);
secd = (secd<10) ? "0"+secd : secd;
totalDuration = mind+":"+secd;
}
//Song starter
MovieClip.prototype.songStarter = function(file) {
if (this.sound_obj) {
this.sound_obj.stop();
delete this.sound_obj;
}
this.sound_obj = new Sound(this);
this.sound_obj.loadSound(file, true);
this.sound_obj.setVolume(90);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
timeInterval = setInterval(timer, 1000, this.sound_obj);
track = this.sound_obj.id3.songname;
artist = this.sound_obj.id3.artist;
this._parent.title_txt.text =artist+" - "+track;
} else {
this._parent.title_txt.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
(mp3list.selectedIndex == songfile.length-1) ? mp3list.selectedIndex=0 : mp3list.selectedIndex++;
};
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
_root.toolTip._visible = true;
setInterval(draggableTip,100);
function draggableTip(){
_root.toolTip._x = _root._xmouse;
}
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._width)*100;
this._parent._parent.sound_mc.sound_obj.setVolume(p);
};
};
this._parent.volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
};
this._parent.volume1.dragger.onReleaseOutside = function() {
_root.toolTip._visible = false;
stopDrag();
};
};
//Button Controls
btn_play.onRelease = function() {
if (pause == true){ // no comment....
this._parent.sound_mc.sound_obj.start(posiP) // start sound from the previously saved position
}
else {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00";
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
};
btn_pause.onRelease = function() { //pause button function
this._parent.sound_mc.sound_obj.stop(); //stop the current sound
posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
pause = true;//set the variable pause to true
}
btn_stop.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
pause = false;
this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
(mp3list.selectedIndex == songfile.length-1) ? mp3list.selectedIndex=0 : mp3list.selectedIndex++;
_root.sound_mc.songStarter(songfile[song_nr]);
};
btn_rev.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr]);
(mp3list.selectedIndex==0)? mp3list.selectedIndex=songfile.length-1 : mp3list.selectedIndex--;
};
//Declare playlist
playlist.load("[url="http://www.fileden.com/files/2007/1/1/579674/Dizzie/mp3playlist.xml"]http://www.fileden.com/files/2007/1/1/5796...mp3playlist.xml[/url]");
setInterval(duration,100);
setInterval(soundStatus,100);
// Project: make a fake equalizer like movie clip for use when music is playing in Flash
// project has lines and toppers, each labeled linex & topperx where x is 1 to 20.
// the lines make up the tall parts of the equalizer, the toppers are just a line placeholder
// for the max value of the lines
// define initial arrays
barboty=new Array(); //holds bottom of each line's _y registration point
randheight=new Array(); //holds randomly generated height of line
toppery=new Array(); //holds _y registration point of topper
decfraction=new Array(); //holds the fraction of random height of line that will be used to decrement the line's height
numbars=40; //defines number of lines
maxheight=115; //defines max height of line
minheight=1; //defines min height of line
gap=2; //defines distance between top of line and topper
topperdrop=.075; //defines value to decrement _y value of topper
numsteps=7; //defines number of steps to decrement height of line
// this function sets values for the heights of each line in the equalizer
function initbars() {
for (i=1;i<_root.numbars+1;i+=1) {
barboty[i]=eval("_root.line"+i)._y;
randheight[i]=Math.random()*maxheight;
toppery[i]=barboty[i]-randheight[i]-gap;
decfraction[i]=randheight[i]/(_root.numsteps);
// set initial line height and position of topper
setProperty(eval("_root.line"+i),_height,_root.randheight[i]+_root.minheight);
setProperty(eval("_root.topper"+i),_y,barboty[i]-randheight[i]-_root.gap-_root.minheight);
}
}
// this function will get executed at the playing frame rate of the movie, even if the movie is stopped
_root.onEnterFrame = function() {
for (j=1;j<_root.numbars+1;j+=1) { //set height of each line for each j in numbars
setProperty(eval("_root.line"+j),_height,_root.randheight[j]);
if (_root.randheight[j]<=_root.minheight) { // if the line height is less than the min, then:
// set line height to the min then redo the line heights etc
setProperty(eval("_root.line"+j),_height,_root.minheight);
_root.initbars(); // the entire function initbars could be placed here if you like rather than being called.
} else { //if not too short, decrement height of lines and position of topper
_root.randheight[j]=_root.randheight[j]-_root.decfraction[j];
setProperty(eval("_root.topper"+j),_y,eval("_root.topper"+j)._y+_root.topperdrop);
}
}
}
