TextFormatting in ActionScript 3 (setTextFormat)

Posted by & filed under Action Script 3, ADOBE FLEX, Flash.

The setTextFormat() method in actionScript 2 used to set the font properties to the text fields.

example:

var txt_format:TextFormat = new TextFormat();//TextFormat class creates new instances of it.

this.createTextField("txt_field", this.getNextHighestDepth(), 0, 0, 180, 80);//creates new text field

txt_format.color = 0x00FF00;
txt_format.size = 20;       //set the text format properties
txt_format.font = "Verdana";

txt_field.selectable = false;
txt_field.multiline = true;
txt_field.autoSize = true;
txt_field.setTextFormat(txt_format);//setTextFormat method set text format properties to the text field
txt_field.text = "Formatting Text in ActionScript 3";

where in the above coding setTextFormat() method sets color, font type and size to the text field.

But in ActionScript 3 setTextFormat() method is no longer exists to set text formats to the Text Field (both dynamic text field and static text field). So ActionScript 3 we are going to set text formats to the text Fields using TextFormat Class. In this tutorial we are going to use both Text Field Class and TextFormat Class to set font type, font color, position and the font size.

Here is the example code……..

In ActionScript 3 defaultTextFormat sets text format to the text Field.

txt_field.defaultTextFormat=txt_format;

var txt_field:TextField = new TextField();
var txt_format:TextFormat = new TextFormat();

addChild(txt_field);

txt_format.font = "Verdana";
txt_format.size = 25;
txt_format.color = 0x0000FF;
txt_format.leftMargin = 30;

txt_field.defaultTextFormat=txt_format; 

txt_field.border = true;
txt_field.x = 50;
txt_field.y = 25;
txt_field.autoSize = TextFieldAutoSize.LEFT;
txt_field.text = "Formatting Text in ActionScript 3";

setTextFormat In ActionScript 3.

Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts

If you want any of my script need to be customized according to your business requirement,

Please feel free to contact me [at] muni2explore[at]gmail.com

Note: But it will be charged based on your customization requirement

Get Updates, Scripts & Other Useful Resources to your Email

Join 10,000+ Happy Subscribers on feedburner. Click to Subscribe (We don't send spam)
Every Email Subsciber could have access to download 100+ demo scripts & all future scripts.

Get Instant Script Download Access!