Jump to content


Photo

XML with links?


  • Please log in to reply
17 replies to this topic

#1 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 02 April 2007 - 06:16 PM

G'day guys,

I'm wondering if you can have links inside a node of an XML? I've got this for each song in my playlist:

<song name ="" band ="" file=".mp3" info ="Click here for more info"/>

...and I'm wondering if where I have "here" I could put <a href='' target='_blank'><u>here</u></a> - at the moment, it breaks the XML, probably because everything's already contained in <> tags.

Any ideas? I'm thinking it'd be great if a song was playing, and some info about the song was displayed, and you could click on a link within the info to learn more :angry:

#2 bezz

bezz

    Young Padawan

  • Members
  • Pip
  • 23 posts
  • Gender:Male
  • Location:Berlin, NJ
  • Interests:Flash, Snowboarding, Paintball, Learning Guitar

Posted 02 April 2007 - 07:14 PM

I don't know about the mp3 player you're using, but it probably could be modified to allow the child node info instead of the attrribute info like so:
<song name ="" band ="" file=".mp3" 
<info>
<a href='' target='_blank'><u>here</u></a>
</info>
</song>


#3 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 02 April 2007 - 07:24 PM

Ah! I'll check that out, thanks mate!!!! I'm using funksoul's mp3 player, of course ;-)

:angry:

#4 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 02 April 2007 - 08:21 PM

It's coming up with "undefined" :(

Here's what I did to the XML (just changed the first one to test):

<?xml version='1.0' encoding='utf-8'?>
<songs>
<song name ="ON MY SIDE NOW" band ="ECLIPTIC" file="mp3/onmyside.mp3" 
<info>
<a href='' target='_blank'><u>here</u></a>
</info>
</song>
<song name ="THE FLOOD" band ="ECLIPTIC" file="mp3/theflood.mp3" info ="From Ecliptic's debut album"/>
<song name ="THE POWER IN HER HAND" band ="ECLIPTIC" file="mp3/thepower.mp3" info ="From Ecliptic's debut album"/>
<song name ="MUSE" band ="ECLIPTIC" file="mp3/muse.mp3" info ="From Ecliptic's debut album"/>
<song name ="FAILING LIGHT" band ="ECLIPTIC" file="mp3/failinglight.mp3" info ="From Ecliptic's debut album"/>
<song name ="GROWN" band ="ECLIPTIC" file="mp3/grown.mp3" info ="From Ecliptic's debut album"/>
<song name ="IN AND OUT OF EVERYTHING" band ="ECLIPTIC" file="mp3/inandout.mp3" info ="From Ecliptic's debut album"/>
<song name ="GOSPEL SONG" band ="ECLIPTIC" file="mp3/gospelsong.mp3" info ="From Ecliptic's debut album"/>
<song name ="NOT MY IDEA OF FUN" band ="ECLIPTIC" file="mp3/notmyidea.mp3" info ="From Ecliptic's debut album"/>
<song name ="DON'T WANT TO LOSE YOU" band ="ECLIPTIC" file="mp3/loseyou.mp3" info ="From Ecliptic's debut album"/>
<song name ="LOVE IS NOT ENOUGH" band ="ECLIPTIC" file="mp3/loveisnotenough.mp3" info ="From Ecliptic's debut album"/>
<song name ="PULL" band ="ECLIPTIC" file="mp3/pull.mp3" info ="From Ecliptic's debut album"/>

</songs>

I'm thinking I need to change something within the player's actionscript? It looks like this at the moment:

stop();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
	if (success) {
		_global.songname = [];
		_global.songband = [];
		_global.songfile = [];
		_global.songinfo = [];
		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;
			_global.songinfo[i] = playlist.firstChild.childNodes[i].attributes.info;
		}
	}
	_root.createEmptyMovieClip("sound_mc", 1);
	_global.song_nr = random(songfile.length);
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr]);
};
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;
}
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;
}
MovieClip.prototype.songStarter = function(file, name, band, info) {
	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.onEnterFrame = function() {
		if (this.sound_obj.position>0) {
			delete this.onEnterFrame;
			this._parent.display_txt.text = name+" / "+band;
			timeInterval = setInterval(timer, 1000, this.sound_obj);
		} else {
			this._parent.display_txt.text = "loading...";
		}
		if (this.sound_obj.position>0) {
			delete this.onEnterFrame;
			this._parent.info_mc.info_text.text = info;
			timeInterval = setInterval(timer, 1000, this.sound_obj);
		} else {
			this._parent.info_mc.info_text.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++;
		_root.sound_mc.songStarter(songfile[song_nr]);
	};
this.sound_obj.setVolume(50);
};
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 = "";
	this._parent.sound_mc.songStarter(songfile[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_fw.onRelease = function() {
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text = "";
	(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr]);
};
btn_rev.onRelease = function() {
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text = "";
	(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr]);
};
playlist.load("playlist.xml");
setInterval(duration,100);

I reckon the ability to have links would be really handy, so hope I can get it working :angry:

#5 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 03 April 2007 - 12:34 AM

Just put an "infourl" attribute in the xml, and use actionscript to grab that value and input it into the text field that displays the info string. You'll need to have that textfield set to use html, and then have the
"<a href=\"" + infoURL_variable +"\"> " + theInfoVariable + "</a>";

Replace the two variable names with your own...the infoURL_variable being what you add to the xml for the link, and theInfoVariable being the info attribute in the xml.

#6 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 03 April 2007 - 03:22 AM

G'day mate,

How do I fit that into the actionscript for the mp3 player? I've added an "infourl" attribute thusly:

<?xml version='1.0' encoding='utf-8'?>
<songs>
<song name ="" band ="" file=".mp3" info ="here's my info for this track" infourl ="http://"/>
</songs>

...but I'm not sure where in the above actionscript (for the mp3 player( to put the other stuff you were talking about. Bear in mind that it needs to change with the buttons.

Cheers yet again!!! Actually, I think if I can get this working, I'll be able to leave you alone for a while...

:angry:

#7 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 03 April 2007 - 08:09 AM

I made some changes in the code...check em out below. And don't worry about asking for help.....gives me something to do :)

stop();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
	if (success) {
		_global.songname = [];
		_global.songband = [];
		_global.songfile = [];
		_global.songinfo = [];
		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;
			_global.songinfo[i] = playlist.firstChild.childNodes[i].attributes.info;
			// add the following line
			_global.songurl[i] = playlist.firstChild.childNodes[i].attributes.info;
		}
	}
	_root.createEmptyMovieClip("sound_mc", 1);
	_global.song_nr = random(songfile.length);
	// modify the following line
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
};
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;
}
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;
}
// modify the following line
MovieClip.prototype.songStarter = function(file, name, band, info, url) {
	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.onEnterFrame = function() {
		if (this.sound_obj.position>0) {
			delete this.onEnterFrame;
			this._parent.display_txt.htmlText = name+" / "+band;
			timeInterval = setInterval(timer, 1000, this.sound_obj);
		} else {
			this._parent.display_txt.text = "loading...";
		}
		if (this.sound_obj.position>0) {
			delete this.onEnterFrame;
			this._parent.info_mc.info_text.html = true; // add this line
			this._parent.info_mc.info_text.htmlText = "<a href = \"" + url + "\">" + info + "<a/>"; // modify this line
			timeInterval = setInterval(timer, 1000, this.sound_obj);
		} else {
			this._parent.info_mc.info_text.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++;
		_root.sound_mc.songStarter(songfile[song_nr]);
	};
this.sound_obj.setVolume(50);
};
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 = "";
	this._parent.sound_mc.songStarter(songfile[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_fw.onRelease = function() {
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text = "";
	(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr]);
};
btn_rev.onRelease = function() {
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text = "";
	(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr]);
};
playlist.load("playlist.xml");
setInterval(duration,100);


#8 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 03 April 2007 - 09:35 AM

I made some changes in the code...check em out below. And don't worry about asking for help.....gives me something to do :)


Awesome - thanks mate!!

I'm not 100% sure on the syntax for the XML going by your actionscript - is it:

<song name ="" band ="" file=".mp3" info ="" url =""/>

...or:

<song name ="" band ="" file=".mp3" info ="" infourl =""/>

...or something different? I tried both, but they didn't work. Also, am I supposed to be just putting the url (i.e. "http://etc") or "<a href etc"?

Cheers, mate :censored:

#9 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 03 April 2007 - 10:54 AM

Oops...typo:) sorry

// add the following line
_global.songurl[i] = playlist.firstChild.childNodes[i].attributes.info;

change the .info to .url or .infourl .... whatever the attribute name is in the xml file.

Just use "http://..." not the "<a href..."

#10 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 03 April 2007 - 05:05 PM

I had to make a couple of changes, but I got it working, thanks mate!!! :) :) :)

Had to add a _global.songurl = []; near the top, and add songurl[song_nr] to the next and prev buttons.

Also realised that having two "if" statements on the onEnterFrame function was doing weird things to the time display, but I've got that sorted now, as well as an "undefined" problem (didn't have all the childnodes listed in the onSoundComplete function).

Here's my fully working as for those who are interested:

stop();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
	if (success) {
		_global.songname = [];
		_global.songband = [];
		_global.songfile = [];
		_global.songinfo = [];
		_global.songurl = [];
		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;
			_global.songinfo[i] = playlist.firstChild.childNodes[i].attributes.info;
			// add the following line
			_global.songurl[i] = playlist.firstChild.childNodes[i].attributes.url;
		}
	}
	_root.createEmptyMovieClip("sound_mc", 1);
	_global.song_nr = random(songfile.length);
	// modify the following line
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
};
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;
}
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;
}
// modify the following line
MovieClip.prototype.songStarter = function(file, name, band, info, url) {
	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.onEnterFrame = function() {
		if (this.sound_obj.position>0) {
			delete this.onEnterFrame;
			display_txt.htmlText = name+" / "+band;
			info_mc.info_text.html = true; // add this line
			info_mc.info_text.htmlText = "<a href = \"" + url + "\">" + info + "<a/>"; // modify this line
			timeInterval = setInterval(timer, 1000, this.sound_obj);
		} else {
			display_txt.text = "loading...";
			info_mc.info_text.text = "loading...";
		}
	};
	this.sound_obj.onSoundComplete = function() {
		clearInterval(timeInterval);
		timeDisplay_txt.text = "00:00/00:00";
		(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
		_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
	};
this.sound_obj.setVolume(50);
};
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);
	timeDisplay_txt.text = "00:00/00:00";
	this._parent.sound_mc.songStarter(songfile[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_fw.onRelease = function() {
	clearInterval(timeInterval);
	timeDisplay_txt.text = "00:00/00:00";
	(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
};
btn_rev.onRelease = function() {
	clearInterval(timeInterval);
	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], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
};
playlist.load("playlist.xml");
setInterval(duration,100);

You're a legend, Pax!!! :)

Maybe this should be added as an add-on to the mp3 player tutorial?

:winner:

#11 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 03 April 2007 - 09:20 PM

Excellent work and debugging on my few missed parts there mate :) And fire it off to funkysoul...see if he wants to add it in.

Good stuff :winner:

#12 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 03 April 2007 - 11:31 PM

I would, but I don't think he's responding to pms at the moment. Hopefully he'll notice this at some point!

:blush:

#13 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 04 April 2007 - 07:51 AM

Just leave him a pm. As far as I know, he's really busy with work stuff right now, so he'll probably see it when things die down.

#14 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 07 April 2007 - 09:48 AM

Hey Pax,

I just realised that I really need the links to open in a _blank page - can we do that? If so, how?

Cheers mate :)

#15 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 07 April 2007 - 02:58 PM

Should just be able to give your <a href... a target = "_blank"

I'd give that go...see if it works.

#16 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 07 April 2007 - 06:08 PM

You mean inside the XML? There aren't any tags in the XML. If you mean add it to the actionscript, can you show me the syntax?

Cheers, mate :P

#17 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 07 April 2007 - 10:56 PM

info_mc.info_text.htmlText = "<a href = \"" + url + "\" target =\"_blank\">" + info + "<a/>";

#18 boogooloo1

boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 08 April 2007 - 10:08 AM

Worked perfectly, of course - thanks again, mate :P




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users