ActionScript HelloWorld

From Payne.org Wiki

Here's how to do a minimal "Hello World" in Flash/ActionScript 3, using only free command-line tools. The other examples I could find all used Adobe's paid tools, Flash Designer, etc.

First, download the "Flex SDK" from Adobe here. This SDK includes a command-line ActionScript compiler. The SDK is written in Java, and should run on all platforms.

Next, create HelloWorld.as :

package {
 import flash.display.*;
 import flash.text.*;
 public class HelloWorld extends Sprite {
   private var greeting:TextField = new TextField();
   
   public function HelloWorld() {	  
     greeting.text = "Hello World!";
     greeting.x = 100;
     greeting.y = 100;
     addChild(greeting);
   }
 }
}

Compile HelloWorld.as into HelloWorld.swf with this command:

 (path to SDK)/bin/mxmlc HelloWorld.as

Copy HelloWorld.swf to a Web server and access the associated URL with a Flash-enabled browser. You should see the "Hello World" text.

To embed this Flash object in a Web page, use the following HTML fragment:

<object data="HelloWorld.swf"
   type="application/x-shockwave-flash" width="500" height="500" >
   <param name="movie" value="HelloWorld.swf" />
</object>

If you put this text in a local HTML file, you should be able to open it with most browsers (i.e. without needing a Web server).

Personal tools