Set Text Format to TextField with Flash ActionScript 3
Flash Tutorial Content:
In this flash tutorial, we will set some Text Formats (e.g. Text Size, Text Color, Bold, Italic, etc..) to the newly created Text Field object with Flash ActionScript 3. The final result is shown as above.
Flash ActionScript Codes:
///////////////////////////////////////////
///// Create New TextField /////
//////////////////////////////////////////
// Create a textfield object with the name "textField_txt"
var textField_txt:TextField = new TextField();
// Add the new textfield_txt instance to the stage
addChild(textField_txt);
// Add Content to TextField
textField_txt.text = "Hello World";
////////////////////////////////////////////
///// Set BASIC Properties /////
///////////////////////////////////////////
// Set position of TextField (x = Left, y = Top)
textField_txt.x = 150;
textField_txt.y = 200;
// Set width of Text Field
textField_txt.width = 350;
//////////////////////////////////////////
///// Set Other Properties /////
/////////////////////////////////////////
// Text not selectable
textField_txt.selectable = false;
// Text border
textField_txt.border = false;
// Autosize with the text and align to the left.
textField_txt.autoSize = TextFieldAutoSize.LEFT;
///////////////////////////////////////////////
///// Set Text Styling Format /////
//////////////////////////////////////////////
// Create a TextFormat instance (myFormat)
var myFormat:TextFormat = new TextFormat();
// Text size
myFormat.size = 50;
// Text color (hex decimal color code)
myFormat.color = 0xCC0000;
// Set to Italic font
myFormat.italic = true;
// Set to Bold
myFormat.bold = true
///// Set the Format now /////
textField_txt.setTextFormat(myFormat);
Download Flash Source File:
Remarks:
This is the end of the second series of Flash ActionScript 3 tutorial.