html parser v1.1 with external links parsing
by gabriele venier, idea: me
// ---------------------------------------------------------------------
// sample text
// ---------------------------------------------------------------------
var htmlContent="<FONT face='Tahoma'><FONT color='#ff2b00' size='21'><STRONG><IMG width='211' height='109' src='
http://www.adbusters.org/home/board_211x109.jpg'>Cinema | Movies</STRONG><FONT color='#000000'><FONT size='9'><BR><STRONG><FONT size='12'> <BR></FONT>- YARD MOVEMENTS 2005 <BR></STRONG><FONT size='15'><STRONG><A href='
http://www.yourdomain.com/test.php?jkl= ... '>Immagini video dal mondo del reggae</A></STRONG></FONT><BR>Ogni giorno dalle ore 15:00 presso la 'Tenda Incontri' <BR>A cura di Mimmo Pizzutilo <BR><BR><STRONG>- ROTOTOM NIGHT MOVIES 2005</STRONG> <BR><FONT size='15'><STRONG><A href='/index.php?id=7,322,0,0,1,0'>Visioni di madre terra fra ambiente e paesaggio. </A></STRONG></FONT><BR>Ogni notte dalle ore 02:00, presso la 'Tenda Incontri' <BR>A cura di Mimmo Pizzutilo <BR><BR><BR><BR></FONT></FONT></FONT></FONT>";
// ---------------------------------------------------------------------
// loading functions
// ---------------------------------------------------------------------
function gotoURL(id){
trace("Getting a result in the same page with id number: "+id);
}
function winOpen(url){
trace("Opening new window to url: "+url);
}
// ---------------------------------------------------------------------
// parsing functions
// ---------------------------------------------------------------------
function replaceUrl(doc:String):String{
var ref_doc, i, f, ts,txt, id, http, comma, url
ref_doc = doc.toLowerCase();
i = ref_doc.indexOf("<a");
if(i == -1)
return doc;
f = ref_doc.indexOf("</a>", i);
ts = doc.substring(i,f+4)
txt = ts.substring(ts.indexOf(">",1)+1, ts.indexOf("<", 1));
http = ts.indexOf("http://");
if(http!=-1){
url = ts.substring(http, ts.indexOf(ts.substr(http-1, 1), http));
return String(doc.slice(0,i)+"<A HREF=\"asfunction:winOpen,"+ url +" \">"+ txt +"</A>"+arguments.callee(doc.slice(f+4)));
}
comma = ts.indexOf(",")
if(comma==-1)
return String(doc.slice(0,f+4)+arguments.callee(doc.slice(f+4)));
id = ts.substring(comma+1, ts.indexOf(",", comma+1))
return String(doc.slice(0,i)+"<A HREF=\"asfunction:gotoURL,"+ id +" \">"+ txt +"</A>"+arguments.callee(doc.slice(f+4)));
}
_root.createTextField("content_tf", 0, 0,0,450,350);
_root.content_tf.multiline = true;
_root.content_tf.wordWrap = true;
_root.content_tf.html = true;
_root.content_tf.htmlText = replaceUrl(htmlContent);
// thanks again to gabriele!!
