Home arrow Flash arrow Page 4 - Working with Text and HTML in Flash
FLASH

Working with Text and HTML in Flash


There are a variety of ways to manipulate text and HTML with Flash that allow you to expand the capabilities of your website. Adi Reddy Mora goes over some of the most common ones.

Author Info:
By: Adi Reddy Mora
Rating: 4 stars4 stars4 stars4 stars4 stars / 118
May 04, 2005
TABLE OF CONTENTS:
  1. · Working with Text and HTML in Flash
  2. · Creating text fields at runtime
  3. · Using TextFormat Class
  4. · Formatting Text using HTML
  5. · Supported HTML tags
  6. · Embedding media in text fields

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Working with Text and HTML in Flash - Formatting Text using HTML
(Page 4 of 6 )

Flash Player supports a subset of standard HTML tags such as <b>, <p>and <li>that you can use to style text in any dynamic or input text field.

Flash Player also supports the <textformat>tag, which lets you apply paragraph formatting styles of the TextFormat class to HTML enabled text fields.

To use HTML in a text field, you must enable the text field’s HTML formatting either by selecting the Render Text as HTML option in the Property panel or by setting the text field’s htmlproperty to true using ActionScript. To insert HTML into a text field use the TextField.htmlTextproperty.

For example, the following code enables HTML formatting for a text field named sample _txtand then assigns some HTML to the text field using font tags.

sample_txt.html = true;
sample_txt.htmlText =
"<font face = 'Times New Roman' size = '24' color = '#003366'>
This is how you assign HTML text to a text field.</font>";

Attributes of HTML tags must be enclosed in double (") or single (') quotation marks. Attribute values without quotation marks can produce unexpected results, such as improper rendering of text. For example, the following HTML snippet cannot be rendered properly by Flash Player because the value assigned to the alignattribute ( left) is not enclosed in quotation marks:

sample_txt.htmlText = "<p align=left>This is left-aligned text</p>";

If you enclose attribute values in double quotation marks, you must escape the quotation marks ( \"). Either of the following examples are acceptable:

sample_txt.htmlText = "<p align='left'>This uses single quotes</p>";
sample_txt.htmlText = "<p align=\"left\">
This uses escaped double quotes</p>";

It’s not necessary to escape double quotation marks if you’re loading text from an external file. It’s necessary only if you’re assigning a string of text in ActionScript.


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials