Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 178

Programming actionscript 3.0
Table of Contents

Advertisement

Working with text
The TextField class, which is in the flash.text package, lets you work with dynamic and input
text fields. Note that there is also a StaticText class in the flash.text package. However, you
cannot instantiate StaticText objects in ActionScript; these are created in the Flash authoring
tool.
As the following example shows, you can use a TextFormat object to set formatting for an
entire TextField or for a range of text:
var tf:TextField = new TextField();
tf.text = "Hello Hello";
var format1:TextFormat = new TextFormat();
format1.color = 0xFF0000;
var format2:TextFormat = new TextFormat();
format2.font = "Courier";
tf.setTextFormat(format1);
var startRange:uint = 6;
tf.setTextFormat(format2, startRange);
addChild(tf);
Text fields can contain either plain text or HTML-formatted text. Plain text is stored in the
property of the instance, and HTML text is stored in the
property.
text
htmlText
You can apply CSS style sheets to HTML text by using a StyleSheet object. For example:
var style:StyleSheet = new StyleSheet();
var styleObj:Object = new Object();
styleObj.fontSize = "bold";
styleObj.color = "#FF0000";
style.setStyle(".darkRed", styleObj);
delete styleObj;
var tf:TextField = new TextField();
tf.styleSheet = style;
tf.htmlText = "<span class = 'darkRed'>Red</span> apple";
addChild(tf);
For more information, see the TextField class in the ActionScript 3.0 Language Reference.
178
Display Programming

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents