formatting html links using cdata
I am parsng a xml document that has html along with text, I am bringing the xml into a dynamic text field. I can retrive the same data from cdata tags as well.

I get the links into my document ok but I need to color the links so user can tell they are links.

Know anyway to do this?

MAybe a function that will take your text, look for the hrefs and add the color thing in the text.

anyone devloped this or know of a workaround?

I unfortunatly cannot modify my xml

Example xml and .fla here:

http://lincart.com/xml_feed_samples.zip

Here is a srting prototype I found that might do what I need but I cannot figure out how to implement???



String.prototype.makeClickable = function(){
var tmp = this.split(" ");
for(var i = 0; i < tmp.length; i++){
if(tmp[i].indexOf("www.") != -1 && tmp[i].indexOf("http://") == -1){
tmp[i] = "<font color=\"#0000FF\"><u><a href='http://"+tmp[i]+"' target='_blank'>"+tmp[i]+"</a></u></font>";
}else if(tmp[i].indexOf("http://") != -1 || tmp[i].indexOf("ftp://") != -1){
tmp[i] = "<font color=\"#0000FF\"><u><a href='"+tmp[i]+"' target='_blank'>"+tmp[i]+"</a></u></font>";
} else if (tmp[i].indexOf("@") != -1 && tmp[i].charAt(0) != "@" && tmp[i].charAt(tmp[i].length-1) != "@") {
tmp[i] = "<font color=\"#0000FF\"><u><a href='mailto:"+tmp[i]+"'>"+tmp[i]+"</a></u></font>";
}
}
return tmp.join("&nbsp;");
}

how would it apply to my code?

do I assign the tmp var to my var?


//frame 1 parse xml

function Article(id, news_item) {
this.id = id;
this.news_item = news_item;
}

function makeArray(success) {
var i, j, mainTag, id, news_item;
if (success) {
for (i=0; i<=moXML.childNodes.length; i++) {
if (this.childNodes[i].nodeValue == null && this.childNodes[i].nodeName == "idj_news_feed") {
mainTag = this.childNodes[i];
}
}

for (i=0; i<=mainTag.childNodes.length; i++) {
if (mainTag.childNodes[i].nodeName == "record") {
articleTag = mainTag.childNodes[i];
id = articleTag.attributes["id"];
for (j=0; j<articleTag.childNodes.length; j++) {
if (articleTag.childNodes[j].nodeName != null) {
if (articleTag.childNodes[j].nodeName == "news_item") {
news_item = articleTag.childNodes[j].firstChild.nodeValue;
}
}
}
thisArticle = new Article(id, news_item);
articles.push(thisArticle);
delete thisArticle;
}
}
_root.gotoAndStop("showArticles");
}
}

// articles is an array of Article objects
var articles = [];

// read xml and display when loaded
moXML = new XML();
moXML.ignoreWhite = true;
moXML.onLoad = makeArray;
moXML.load("demoNews.xml");
stop();

// frame label showArticles

news = "";
for (i=0; i<articles.length; i++) {
news += "<a href='" + articles[i].link + "'>" + articles[i].news_item + "</a><br>";
//news += " <font color='#cccccc'>(" + articles[i].source + ")</font><br>";
}
scroller.html = true;
scroller.htmlText = this.news;
stop();


thanks for the help I am still getting a grasp on coding.