13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Using the TextField class<br />

Displaying HTML text<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The flash.text.TextField class has an htmlText property that you can use to id<strong>en</strong>tify your text string as one containing<br />

HTML tags for formatting the cont<strong>en</strong>t. As in the following example, you must assign your string value to the htmlText<br />

property (not the text property) for Flash Player or AIR to r<strong>en</strong>der the text as HTML:<br />

var myText:String = "This is some cont<strong>en</strong>t to r<strong>en</strong>der as HTML text.";<br />

myTextBox.htmlText = myText;<br />

Flash Player and AIR support a subset of HTML tags and <strong>en</strong>tities for the htmlText property. The<br />

flash.text.TextField.htmlText property description in the ActionScript 3.0 Refer<strong>en</strong>ce provides detailed<br />

information about the supported HTML tags and <strong>en</strong>tities.<br />

Once you designate your cont<strong>en</strong>t using the htmlText property, you can use style sheets or the textformat tag to<br />

manage the formatting of your cont<strong>en</strong>t. For more information, see “Formatting text” on page 380.<br />

Using images in text fields<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Another advantage to displaying your cont<strong>en</strong>t as HTML text is that you can include images in the text field. You can<br />

refer<strong>en</strong>ce an image, local or remote, using the img tag and have it appear within the associated text field.<br />

The following example creates a text field named myTextBox and includes a JPG image of an eye, stored in the same<br />

directory as the SWF file, within the displayed text:<br />

package<br />

{<br />

import flash.display.Sprite;<br />

import flash.text.*;<br />

public class TextWithImage ext<strong>en</strong>ds Sprite<br />

{<br />

private var myTextBox:TextField;<br />

private var myText:String = "This is some cont<strong>en</strong>t to test and<br />

seewhat can be<br />

r<strong>en</strong>dered.You should see an eye image and some HTML text.";<br />

}<br />

}<br />

public function TextWithImage()<br />

{<br />

myTextBox.width = 200;<br />

myTextBox.height = 200;<br />

myTextBox.multiline = true;<br />

myTextBox.wordWrap = true;<br />

myTextBox.border = true;<br />

}<br />

addChild(myTextBox);<br />

myTextBox.htmlText = myText;<br />

The img tag supports JPEG, GIF, PNG, and SWF files.<br />

Last updated 6/6/2012<br />

375

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!