Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Align TextField to Stage Center with Flash ActionScript 3

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

So far so good. Let's try to to align the TextField to the center of the stage of the Flash Movie with Flash ActionScript 3. Of course the Text Field can be aligned to any position on the stage of the Flash Movie you like.

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:

Flash Source File hello-world-3.fla

Remarks:

This is the end of the first series of Flash ActionScript 3.0 tutorial.