知道何时单击文本字段中的超链接?

时间:2021-10-05 07:16:33

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

在Flash中,当用户单击TextField中的超链接时是否有任何事件?

4 个解决方案

#1


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

有:TextEvent.LINK,但它只适用于前缀为“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.

如果你不使用“event:”语法提取外部数据,你可以轻松编写一个快速的RegExp来添加它。

#2


It seems possible, check out the reference.

看来有可能,查看参考资料。

#3


It is possible to use the TextField event "link" - it is dispatched when a user clicks a hyperlink within the TextField.

可以使用TextField事件“链接” - 当用户单击TextField中的超链接时调度它。

A great example is supplied in the Adobe site.

Adobe网站提供了一个很好的例子。

#4


Here is code that replaces hrefs with "event:" prefixes (as suggested by geraldalewis above):

以下代码用“event:”前缀替换hrefs(如上面geraldalewis所建议的):

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.)

请注意,我确保撤消已经包含“event:”的href的替换。 (我本可以在正则表达式中使用负向前瞻断言,但我很懒。)

#1


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

有:TextEvent.LINK,但它只适用于前缀为“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.

如果你不使用“event:”语法提取外部数据,你可以轻松编写一个快速的RegExp来添加它。

#2


It seems possible, check out the reference.

看来有可能,查看参考资料。

#3


It is possible to use the TextField event "link" - it is dispatched when a user clicks a hyperlink within the TextField.

可以使用TextField事件“链接” - 当用户单击TextField中的超链接时调度它。

A great example is supplied in the Adobe site.

Adobe网站提供了一个很好的例子。

#4


Here is code that replaces hrefs with "event:" prefixes (as suggested by geraldalewis above):

以下代码用“event:”前缀替换hrefs(如上面geraldalewis所建议的):

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.)

请注意,我确保撤消已经包含“event:”的href的替换。 (我本可以在正则表达式中使用负向前瞻断言,但我很懒。)