Hello World in ActionScript

Our first program will print the classic “hello world” message. Here’s the full source code.

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    
    public class HelloWorld extends Sprite {
        public function HelloWorld() {
            var textField:TextField = new TextField();
            textField.text = "hello world";
            addChild(textField);
        }
    }
}

To run the program, compile the ActionScript code into a SWF file using the MXMLC compiler.

$ mxmlc HelloWorld.as
$ ls
HelloWorld.swf    HelloWorld.as

We can then run the SWF file using a web browser or a SWF player.

$ open HelloWorld.swf

Now that we can run and build basic ActionScript programs, let’s learn more about the language.