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 />

Formatting text<br />

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

You have several options for programmatically formatting the display of text. You can set properties directly on the<br />

TextField instance—for example, the TextFIeld.thickness, TextField.textColor, and TextField.textHeight<br />

properties.Or you can designate the cont<strong>en</strong>t of the text field using the htmlText property and use the supported<br />

HTML tags, such as b, i, and u. But you can also apply TextFormat objects to text fields containing plain text, or<br />

StyleSheet objects to text fields containing the htmlText property. Using TextFormat and StyleSheet objects provides<br />

the most control and consist<strong>en</strong>cy over the appearance of text throughout your application. You can define a<br />

TextFormat or StyleSheet object and apply it to many or all text fields in your application.<br />

Assigning text formats<br />

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

You can use the TextFormat class to set a number of differ<strong>en</strong>t text display properties and to apply them to the <strong>en</strong>tire<br />

cont<strong>en</strong>ts of a TextField object, or to a range of text.<br />

The following example applies one TextFormat object to an <strong>en</strong>tire TextField object and applies a second TextFormat<br />

object to a range of text within that TextField object:<br />

var tf:TextField = new TextField();<br />

tf.text = "Hello Hello";<br />

var format1:TextFormat = new TextFormat();<br />

format1.color = 0xFF0000;<br />

var format2:TextFormat = new TextFormat();<br />

format2.font = "Courier";<br />

tf.setTextFormat(format1);<br />

var startRange:uint = 6;<br />

tf.setTextFormat(format2, startRange);<br />

addChild(tf);<br />

The TextField.setTextFormat() method only affects text that is already displayed in the text field. If the cont<strong>en</strong>t<br />

in the TextField changes, your application might need to call the TextField.setTextFormat() method again to<br />

reapply the formatting. You can also set the TextField defaultTextFormat property to specify the format to be used<br />

for user-<strong>en</strong>tered text.<br />

Applying cascading style sheets<br />

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

Text fields can contain either plain text or HTML-formatted text. Plain text is stored in the text property of the<br />

instance, and HTML text is stored in the htmlText property.<br />

You can use CSS style declarations to define text styles that you can apply to many differ<strong>en</strong>t text fields. CSS style<br />

declarations can be created in your application code or loaded in at run time from an external CSS file.<br />

Last updated 6/6/2012<br />

380

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

Saved successfully!

Ooh no, something went wrong!