Problem
You want to use
HTML tags in text fields or text areas.
Solution
For text area components, set the html parameter to TRue using the Component Inspector panel. Then assign the HTML text to the component's text parameter.
For text fields, activate the Render Text as HTML option within the Property inspector. Or set its html property to TRue using ActionScript. In either case, after you've set the text field to render HTML, you can then assign the HTML text to the field's htmlText ActionScript property. (You cannot assign HTML text to a text field at authoring time.)
Discussion
You can instruct Flash to render text field and text area content as HTML rather than plain text, which is an effective and relatively simple way to apply some formatting to your text without having to use extensive ActionScript. For example, you can add hyperlinks, color, and style changes all with basic HTML tags.
There are two main steps in using HTML in your text fields and text areas. The steps in either case amount to basically the same thingtelling Flash to render the text within the instance as HTML rather than plain text, and assigning the HTML to the instance. However, the steps are slightly different depending on whether you are using a text field or a text area.
If you are using a text area, complete the following two steps:
With the text area selected, set the html parameter to TRue using the Component Inspector panel. Assign the HTML text to the text area by way of the text property within the Component Inspector panel.
If you are using a text field, complete the following two steps:
Tell Flash that it should render the text for that field as
HTML. You can accomplish this one of two ways: Select the text field with the Selection tool, and select the Render as HTML option to the right of the Selectable option and the Line type menu in the Property inspector. Use ActionScript to set the text field's html property to true:
tField.html = true;
Assign the HTML value to the text field's htmlText property. When you have instructed Flash to render the text field as HTML, you should not assign the HTML code to the text property as you would do for plain text. Instead, use the htmlText property as shown here:
tField.htmlText = "<font color='#0000FF'>blue text is fun<font>";
The following HTML
tags are supported by dynamic text in Flash:
<a>
-
Use this tag for creating hyperlinks. Flash's support of the tag includes the following attributes:
href
-
The URL to which you want to hyperlink. You may use standard http or https protocols. You can also specify the mailto, javascript, or asfunction directives.
target
-
The name (exp 3pod.com) of the window into which the hyperlink should be opened. If no target is specified, then the link is opened in the same window as the Flash movie.
<b>
Use this tag to embolden text.
<font>
-
Flash's support of the <font> tag includes three attributes:
color
-
Use the color attribute to set the color of text. The value must be a hexadecimal value that begins with a # (e.g., #0000FF for blue and #00FF00 for green).
face
-
The face attribute sets the name (exp 3pod.com) of the font. You can specify any font name (exp 3pod.com), comma-delimited list of font names, or one of the three Flash font groups (_serif, _sans, or _typewriter.)
size
-
The size attribute sets the size of the text.
<i>
-
Use this tag to italicize text.
<img>
-
Use this tag to display an external .jpeg file or .swf file, or to display a movie clip within a text field or text area. Flash supports the following attributes for the <img> tag:
align
-
You can optionally specify how to align the content within the text field or text area. Choose from left (default) or right.
height
-
The height to which you want to resize the content.
hspace
-
The number of pixels of space to the left and right of the content. The default is 8.
id
-
The instance name (exp 3pod.com) by which the image or movie clip can be addressed using ActionScript. This attribute is necessary only if you plan to target the content with code.
src
-
The URL of the .jpeg or .swf file to load and display. Optionally, you may specify the linkage identifier of a movie clip symbol in the library.
width
-
The width to which you want to resize the content.
vspace
-
The number of pixels of space above and below the content. The default is 8.
<li>
-
Use the <li> tag to create a bulleted list. Flash does not support the <ul> and <ol>
tags to differentiate between an ordered and unordered list.
<p>
-
Use the <p> tag to create a new paragraph. Flash supports the following attributes for the tag:
align
-
Specify left, center,or right to indicate how you want the text to align within the text field or text area. The default is left.
class
-
The class attribute allows you to apply CSS formatting to the text. In order to use the class attribute you should first apply a StyleSheet object to the text field. CSS works only with text fields, and not with text areas. You can read more about using CSS with text fields in Recipe 8.15.
<span>
-
Use this tag to apply CSS
formatting to your
HTML text. In order to apply CSS, you must first have applied a StyleSheet object to the text field. The tag only works with text fields, and not with text areas. Flash supports the following attribute for the span tag:
class
-
The CSS class you want to apply to the text.
<u>
-
Use this tag to underline text.
|