Hello, World! in ECMAScript

Example for versions Adobe Flex 3.4

While the constructor Main() is called first, it contains a small routine that causes initialization to occurr only if it is created on a stage or when it is added to a stage.

“Hello World” is created via a TextField object.

package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.MovieClip;
	import flash.text.TextField;
	
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);

			// entry point		
			var tf:TextField = new TextField();
			tf.text = "Hello World!";
			tf.x = 200;
			tf.y = 20;
			this.addChild(tf);
		}
	}
}