Align TextField to Stage Center with Flash ActionScript 3
Flash Tutorial Content:
Flash ActionScript Codes:
// Add Content to Text Field
textField_txt.text = "Hello World";
// Autosize TextField with the text and align to CENTER.
textField_txt.autoSize = TextFieldAutoSize.CENTER;
//////////////////////////////////////////////////////////
///// Align TextField to Stage Center /////
/////////////////////////////////////////////////////////
// Find the center co-ordinate of Stage
var stageCenter_x:Number = stage.stageWidth/2;
var stageCenter_y:Number = stage.stageHeight/2;
// Find the center co-ordinate of TextField
var textCenter_x:Number = textField_txt.width/2;
var textCenter_y:Number = textField_txt.height/2;
// Align TextField to Center
// Note: textField_txt.x and textField_txt.y is the Top Left corner of TextField
textField_txt.x = stageCenter_x - textCenter_x;
textField_txt.y = stageCenter_y - textCenter_y;
Download Flash Source File:
Remarks:
This is the end of the first series of Flash ActionScript 3.0 tutorial.