AddThis Social Bookmark Button
 Loading HTML-formatted text in a dynamic text field

download source files
download source files

Although it is very easy to format your text at authoring time, it is not the case when you load text dynamically in a dynamic text field. The best way to format your text in that case is to use HTML. The following tutorial shows you how to format and load HTML-formatted text in a dynamic text field.

Tutorial

1. Create a new FLA

2. Create a text field, make it dynamic and in the instance name field enter "myText". (fig1)

dynamic text field fig1

To render your dynamic text as HTML you need to select your text field and then to click on the little button "Render as HTML" in the properties panel. You need to set it as Multiline too. (fig2)

render as HTML fig2

Alternatively you can enable HTML rendering and multiline with actionscript using the following code :
myText.html = true;
myText.multiline = true;

3. Before we start creating some HTML to import in our dynamic text field let's consider some important points :

The Flash Player supports a subset of standard HTML tags such as <p> and <li> which you can use to style text in any dynamic or input text field. Text fields in Flash Player 7 and later also support the <img> tag, which lets you embed image files (JPEG, GIF, PNG), SWF files, and movie clips in a text field. Flash Player automatically wraps text around images embedded in text fields in much the same way that a web browser wraps text around embedded images in an HTML page.

To render HTML correctly, you must use the correct syntax. Attributes of HTML tags must be enclosed in double (") or single (') quotation marks. For example :
myText.htmlText = "<p align='left'>This is a left-aligned text</p>";
If you enclose attribute values in double quotation marks, you must escape the quotation marks (\"). Either of the following ways of doing this is acceptable:
myText.htmlText = "<p align='left'>This uses single quotes</p>";
myText.htmlText = "<p align=\"left\">This uses escaped double quotes</p>";
myText.htmlText = '<p align="left">This uses outer single quotes</p>';
myText.htmlText = '<p align=\'left\'>This uses escaped single quotes</p>';

The supported HTML tags are :

  • Anchor tag
    • href A string of up to 128 characters that specifies the URL of the page to load in the browser. The URL can be either absolute or relative to the location of the SWF file that is loading the page. An example of an absolute reference to a URL is http://www.Adobe.com; an example of a relative reference is /index.html.
    • target Specifies the name of the target window where you load the page. Options include _self, _blank, _parent, and _top. The _self option specifies the current frame in the current window, _blank specifies a new window, _parent specifies the parent of the current frame, and _top specifies the top-level frame in the current window.

  • Bold tag
    The <b> tag renders text as bold

  • Break tag
    The <br> tag creates a line break in the text field. You must set the text field to be a multiline text field to use this tag.

  • Font tag
    The <font> tag specifies a font or list of fonts to display the text. The font tag supports the following attributes:

    • color Only hexadecimal color (#FFFFFF) values are supported.
    • face Specifies the name of the font to use. You can specify a list of comma-delimited font names, in which case Flash Player selects the first available font. If the specified font is not installed on the user's computer system or isn't embedded in the SWF file, Flash Player selects a substitute font.
    • size Specifies the size of the font in pixels.
AddThis Social Bookmark Button
If you think this page is providing useful information, don't hesitate to leave a comment.
flashvalley
 
Copyright ©2006-2008 flashvalley.com - All rights reserved