Hello, I just finished building out a very basic XML player from a tutorial. I apologize for the long post but there seems to be no way around it. The AS is as follows:
stop();
playlist = 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* = playlist.firstChild.childNodes*.attributes.name;
_global.songfile* = playlist.firstChild.childNodes*.attributes.file;
trace(songname*+" "+songfile*);
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_root.sound_mc.sound_obj = new Sound();
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
MovieClip.prototype.songStarter = function(file, name) {
this.sound_obj.loadSound(file, true);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
_root.scrolltext.display_txt.text = name;
} else {
_root.scrolltext.display_txt.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() {
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
};
btn_play.onRelease = function() {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
btn_stop.onRelease = function() {
this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
btn_rev.onRelease = function() {
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
playlist.load("playlist.xml");
AND THE XML:
<?xml version="1.0" encoding="UTF-8"?>
<songs>
<song name ="Test1" file="test1.mp3" />
<song name ="Test2" file="test2.mp3" />
</songs>
I would like to add an artist text field. Obviously would start with the XML:
<?xml version="1.0" encoding="UTF-8"?>
<songs>
<song name ="Test1" file="test1.mp3" **artist="Test Artist 1"** />
<song name ="Test2" file="test2.mp3" **artist="Test Artist 2"** />
</songs>
Then would have to edit the AS:
stop();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
_global.songname = [];
_global.songband = [];
_global.songfile = [];
[COLOR=Red]_global.songartist=[];[/COLOR]
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname* = playlist.firstChild.childNodes*.attributes.name;
_global.songfile* = playlist.firstChild.childNodes*.attributes.file;
[COLOR=Red]_global.songartist* = playlist.firstChild.childNodes*.attributes.artist;[/COLOR]
trace(songname*+" "+songfile*)[COLOR=Red]+" "+songartist*);[/COLOR]
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_root.sound_mc.sound_obj = new Sound();
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr][COLOR=Red], songartist[song_nr])[/COLOR];
};
MovieClip.prototype.songStarter = function(file, name, [COLOR=Red]artist[/COLOR]) {
this.sound_obj.loadSound(file, true);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
_root.scrolltext.display_txt.text = name;
[COLOR=Red] _root.scrolltext.artist_txt.text = artist;
}
else {
_root.scrolltext.display_txt.text = "loading...";
_root.scrolltext.artist_txt.text = "loading...";
}[/COLOR]
};
this.sound_obj.onSoundComplete = function() {
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr][COLOR=Red], songartist[song_nr][/COLOR]);
};
};
btn_play.onRelease = function() {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr][COLOR=Red], songartist[song_nr][/COLOR]);
};
btn_stop.onRelease = function() {
this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr][COLOR=Red], songartist[song_nr][/COLOR]);
};
btn_rev.onRelease = function() {
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr][COLOR=Red], songartist[song_nr][/COLOR]);
};
playlist.load("playlist.xml");
please critique (not sure if I added the XML artist properly). Thanks so much for all your help…