Flex 3: Creating Clickable Links From Typed URLs
FlexHere's a very basic method used to convert URLs in a string of typed text to clickable links. This can be a pretty helpful thing in, say, a chat application.
public function URLsToLinks(theString:String):String {
var fullRE:String = "(https?)://([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+([a-zA-Z]{2,9})(:\\d{1,4})?([-\\w/#~:.?+=&%@~]*)";
var urlPattern:RegExp = new RegExp(fullRE,"ig");
var result:String = theString.replace(urlPattern,'<a href="$&" target="_blank"><font color="#0000FF"><u>$&</u></font></a>');
trace('[RegEx Result] ' + result);
return result;
}
To use the method just invoke it as such:
var formattedString:String = URLsToLinks(textInput.text);
**Edit 8/22/2008 5:12pm**
The first method I posted was good, but it didn't find and replace URLs with a query string. Thanks to my RegEx Pocket Reference and Ben Nadel ( @bennadel ) via twitter, the method you see above should handle just about any long URL.




Loading....