9.25.在文本框里添加超链接

问题
我想在文本框里加入超链接
解决办法
利用HTML <a href> 标签设置文本框的htmlText 属性,也可用TextFormat 对象的url属性
讨论
两种方法都有个前提那就是文本框的html 属性必须先设为TRue:
+展开
-ActionScript
field.html = true;

在文本框的htmlText 属性里设置HTML超链接标签<a href>:
+展开
-ActionScript
field.htmlText = "<a href='http://www.rightactionscript.com'>Website</a>";

还可指定目标窗口的打开方式:
+展开
-ActionScript
field.htmlText = "<a href='http://www.rightactionscript.com' target='blank'>Website</a>";

当鼠标移到超链接上时鼠标图标会变成手型图标,下面给超链接加上下划线和颜色:
+展开
-ActionScript
var htmlLink:String = "<font color='#0000FF'><u>";
htmlLink += "<a href='http://www.rightactionscript.com'>Website</a>";
htmlLink += "</u></font>";
field.htmlText = htmlLink;

另外用TextFormat对象的url属性也可达到HTML标签同样的效果:
+展开
-ActionScript
field.text = "Website";
var formatter:TextFormat = new TextFormat( );
formatter.url = "http://www.rightactionscript.com/";
field.setTextFormat(formatter);

通过TextFormat 对象的target 属性设置链接打开窗口方式:
+展开
-ActionScript
field.text = "Website";
var formatter:TextFormat = new TextFormat( );
formatter.url = "http://www.rightactionscript.com/";
formatter.target = "_blank";
field.setTextFormat(formatter);

加上颜色和下划线:
+展开
-ActionScript
field.text = "Website";
var formatter:TextFormat = new TextFormat( );
formatter.color = 0x0000FF;
formatter.underline = true;
formatter.url = "http://www.rightactionscript.com/";
field.setTextFormat(formatter);

超链接可以是http或https协议,也可以是其他协议如邮件消息:
+展开
-ActionScript
field.text = "email";
var formatter:TextFormat = new TextFormat( );
formatter.color = 0x0000FF;
formatter.underline = true;
formatter.url = "mailto:joey@person13.com";
field.setTextFormat(formatter);

用CSS是最完美的,它提供了超链接的a:link, a:active,和a:hover 样式:
+展开
-ActionScript
var css:StyleSheet = new StyleSheet( );
css.parseCSS("a {color: #0000FF;} a:hover {text-decoration: underline;}");
field.styleSheet = css;
field.html = true;
field.htmlText = "<a href='http://www.rightactionscript.com'>Website</a>";

加支付宝好友偷能量挖...


评论(1)网络
阅读(119)喜欢(0)flash/flex/fcs/AIR