views:

400

answers:

4

In Flash, is there any event when the user clicks a hyperlink in a TextField?

+3  A: 

There is: TextEvent.LINK, but it only works with links prepended with "event:".

tf.htmlText = "<a href=\"event:http://www.example.com\"&gt;Example&lt;/a&gt;&lt;br&gt;";

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.

+1  A: 

It seems possible, check out the reference.

Zárate
+1  A: 

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.

fixed
+1  A: 

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