In Flash, is there any event when the user clicks a hyperlink in a TextField?
Asked
Active
Viewed 1,003 times
4 Answers
3
There is: TextEvent.LINK, but it only works with links prepended with "event:".
tf.htmlText = "<a href=\"event:http://www.example.com\">Example</a><br>";
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html
If you're pulling in external data not using "event:" syntax, you could probably easily write a quick RegExp to add it in.

geraldalewis
- 838
- 1
- 6
- 9
1
Here is code that replaces hrefs with "event:" prefixes (as suggested by geraldalewis above):
public static function hrefEvents(s:String):String {
var hrefRegex:RegExp = /href="/gm;
var output:String = s.replace(hrefRegex, "href=\"event:");
var dupe:RegExp = /event:event:/gm;
output = output.replace(dupe, "event:");
return output;
}
Note that I make sure to undo the replace for hrefs that already have "event:" in them. (I could have used a negative look-ahead assertion in the regex, but I was lazy.)

Paul Chernoch
- 5,275
- 3
- 52
- 73
1
It is possible to use the TextField event "link" - it is dispatched when a user clicks a hyperlink within the TextField.
A great example is supplied in the Adobe site.

brokenisfixed
- 653
- 1
- 9
- 21