8.28. Adding a Hyperlink to Text
Problem
You want to hyperlink some of the text displayed in a text field.
Solution
Use HTML <a href> tags within the
object’s htmlText property.
Alternatively, use a TextFormat object with a
value assigned to the url property.
Discussion
Both solutions to this problem require you to set the text
field’s html property to
true:
myTextField.html = true;
If you want to use HTML to add a hyperlink, add an <a href> tag to the text field’s
htmlText property, as follows:
myTextField.htmlText = "<a href=\"http://www.person13.com/\">click here</a>";
You can specify a target window in which to open the link by adding a
target attribute to the <a href> HTML tag. For example:
myTextField.htmlText = "<a href=\"http://www.person13.com/\" target=\"_blank\">click here</a>";
When text is hyperlinked in Flash, the mouse cursor changes to a hand when it is over the linked text. Flash does not inherently provide any indication that the text is linked, as do most HTML browsers (with an underline and color change). For this reason, it is helpful to add HTML markup that underlines and colors the linked text:
htmlLink = "<font color=\"#0000FF\"><u>"; // Add the color and underline. htmlLink += "<a href=\"http://www.person13.com/\">click here</a>"; htmlLink += "</u></font>"; myTextField.htmlText = htmlLink; // Close the color and underline.
You can accomplish the same tasks without HTML by using a
TextFormat object. The
TextFormat class includes a
url property for just this purpose. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access