Found this little bit of RegEx to be really handy.
It strips out http links from your htmlText and replaces it with text events. What’s particularly nice is it also destroys anything else in the a tag – i.e. javascript popup code, target, id, etc…because we don’t want all that stuff in Flash.
This is essentially the replacement for asfunction: from AS2.
var txtBox:TextField = new TextField();
txtBox.addEventListener(TextEvent.LINK,textClicked,false,0,true);
addChild(txtBox);
var linkTxt = "<b><a href='http://www.google.com/'>Google</a></b> link sent as 'event:' instead."
var myTxt = linksToTextEvents(linkTxt);
txtBox.htmlText = myTxt;
function linksToTextEvents(txt:String):String {
trace("BEFORE:",txt);
var regExCompleteLink:RegExp = /<a[^>]+(http:\/\/[^"']+)['"][^>]*>([^<>]*)<\/a>/gi;
var matched:String = txt.replace(regExCompleteLink,"<a href='event:$1'>$2</a>")
trace("AFTER:",matched);
return matched;
}
function textClicked(evt:TextEvent):void {
trace('text clicked!: ' + evt.text)
}
Thanks for writing, I very much liked your newest post. I think you should post more frequently, you evidently have natural ability for blogging!