Thank you Pax for your reply, I have it all working now (text wise), but now I am getting another error:
I made my playlist scrollable via a movieclip, two buttons, and a mask, but seem to be losing where the files are within the project (loss of scope error). I believe it has to do with this line:
_root.sound_mc.songStarter(songfile[this.id], songname[this.id], songartist[this.id], songartwork[this.id]);
Now instead of it just being _root["temp"+i] it is now _root.scrollMovieClip.mc_window["temp"+i].
Here is the full code:
stop();
_soundbuftime = 5; // Buffer in seconds before playing
display_txt.autoSize = "left";
playlist = new XML();
playlist.ignoreWhite = true;
//_global.playlistsize;
playlist.onLoad = function(success) {
if (success) {
_global.songartist = [];
_global.songname = [];
_global.songfile = [];
_global.songartwork = [];
for (var i = 0; i < playlist.firstChild.childNodes.length; i++) {
//_global.playlistsize = playlist.firstChild.childNodes.length;
_global.songartist[i] = playlist.firstChild.childNodes[i].attributes.artist;
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
_global.songartwork[i] = playlist.firstChild.childNodes[i].attributes.artwork;
_root.scrollMovieClip.mc_window.attachMovie("mc_template", "temp"+i, i+50);
eval("temp"+i).id = i;
_root.scrollMovieClip.mc_window["temp"+i]._x = 0;
_root.scrollMovieClip.mc_window["temp"+i]._y = 0 + (i*25);
_root.scrollMovieClip.mc_window["temp"+i].template_txt.text = songname[i];
//_root["temp"+i].template_txt.textColor = 0xDDB55D;
_root.scrollMovieClip.mc_window["temp"+i].onRelease = function(){
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00";
_root.sound_mc.songStarter(songfile[this.id], songname[this.id], songartist[this.id], songartwork[this.id]);
}
trace(songartist[i]+" - "+songname[i]+"\n"+songfile[i]+"\n"+songartwork[i]);
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[0], songname[0], songartist[0], songartwork[0]);
}
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;
}
MovieClip.prototype.songStarter = function(file, name, artist, artwork) {
if(this.sound_obj) {
this.sound_obj.stop();
delete this.sound_obj;
this.sound_obj = new Sound(this);
}
this.sound_obj = new Sound(this);
this.sound_obj.loadSound(file, true);
this.sound_obj.setVolume(0); // Initial volume for fade in
this.onEnterFrame = function() {
if (this.sound_obj.position > 0) {
delete this.onEnterFrame;
this._parent.display_txt.html = true;
// Access the music file information using id3
//track = this.sound_obj.id3.songname;
//artist = this.sound_obj.id3.artist;
this._parent.display_txt.htmlText = "<b>"+artist+"</b> - "+name;
this._parent.display_artwork.html = true;
this._parent.display_artwork.htmlText = "<img src='"+artwork+"' alt='"+artist+"' width='142px' height='142px' />";
timeInterval = setInterval(timer, 1000, this.sound_obj); // Time display
} else {
this._parent.display_txt.text = "loading...";
}
}
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00";
(song_nr==songfile.length-1)? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songartist[song_nr], songartwork[song_nr]);
}
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
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() {
stopDrag();
}
}
function soundStatus() {
var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
if(amountLoaded == 1) {
_root.mc_loadBar.mc_loadBarFill.play();
duration = _root.sound_mc.sound_obj.duration;
position = _root.sound_mc.sound_obj.position;
_root.mc_playHead._width = position / duration * 202 - 1;
}
else
{
_root.mc_loadBar.mc_loadBarFill.stop();
}
}
btn_pause._visible = true; // Initially show pause button as not visible
btn_play.onRelease = function() {
btn_pause._visible = true;
btn_play._visible = false;
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]);
}}
btn_pause.onRelease = 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_pause._visible = false;
btn_play._visible = true;
}
btn_next.onRelease = function () {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text="00:00";
(song_nr==songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songartist[song_nr], songartwork[song_nr]);
_root.mc_playHead._width = 0;
btn_pause._visible = true;
btn_play._visible = false;
}
btn_prev.onRelease = function () {
if(onLoad) { // Fix error loading xml
btn_prev.enabled = false;
}
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00";
(song_nr==0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songartist[song_nr], songartwork[song_nr]);
_root.mc_playHead._width = 0;
btn_pause._visible = true;
btn_play._visible = false;
}
// Scroll window displaying playlist
var scrollAmount;
var pressing;
var scrollLocation;
_root.scrollMovieClip.btn_scrollDown.onRollOver = function() {
pressing = true;
scrollAmount = 3;
}
_root.scrollMovieClip.btn_scrollUp.onRollOver = function() {
if(_root.scrollMovieClip.mc_window._x < _root.scrollMovieClip.mc_window_mask._x)
{
trace(_root.scrollMovieClip.mc_window._x+"\n"+_root.scrollMovieClip.mc_window_mask._x);
pressing = false;
scrollAmount = 0;
}
else
{
pressing = true;
scrollAmount = -3;
}
}
_root.scrollMovieClip.btn_scrollDown.onRollOut = _root.scrollMovieClip.btn_scrollUp.onRelease = function () {
pressing = false;
}
_root.onEnterFrame = function() {
if (pressing) {
_root.scrollMovieClip.mc_window._y -= scrollAmount;
//trace(playlistsize);
}
}
playlist.load("playlist.xml");
setInterval(soundStatus, 100);
I really appreciate any help you can give me.
Thanks!
Brandon