package { // A Document Class file starts by declaring that // it is a package that contains a class ///////////////////////////////////////////////// ///// Define what are needed in the program ///// ///// This is usually done by using import ///// ///////////////////////////////////////////////// // We need to display the TextField object on the stage import flash.display.MovieClip; // We need to use the flash.text classes to display text to TextField import flash.text.*; ////////////////////////////////////////////////////////////////////// ///// Define the Class now. ///// ///// This is a public class so that the Flash Movie can use it. ///// ///// The class name is MyClass. ///// ///// The class name MUST be same as the ActionScript File name ///// ////////////////////////////////////////////////////////////////////// public class MyClass extends MovieClip { ////////////////////////////////////////////////////////////////////// ///// This class contain a function. ///// ///// The function name is also MyClass. ///// ///// If the function name is same as the class name, ///// ///// the function will be executed when the class is initiated. ///// ////////////////////////////////////////////////////////////////////// public function MyClass() { ////////////////////////////////////////// ///// The codes below is exactly the ///// ///// same as previous tutorial ///// ////////////////////////////////////////// // 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 // Note: stage.stageWidth not working with trouble IE 6 //var stageCenter_x:Number=stage.stageWidth / 2; //var stageCenter_y:Number=stage.stageHeight / 2; var stageCenter_x:Number=512 / 2; var stageCenter_y:Number=384 / 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 // Remember that 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; } } }