Every language starts you at the same slightly humiliating checkpoint: put five words on a screen and prove the machine is listening. ActionScript 3 agrees, but it makes you build a small cathedral of boilerplate before it hands over the keys. Here is the entire thing, and then we take it apart with a screwdriver.
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
public class HelloWorld extends Sprite {
public function HelloWorld() {
var format:TextFormat = new TextFormat();
format.size = 24;
format.font = "Helvetica";
var label:TextField = new TextField();
label.defaultTextFormat = format;
label.text = "Hello, world.";
label.x = 20;
label.y = 20;
label.width = 320;
label.selectable = false;
addChild(label);
}
}
}
What all of that ceremony buys you
The package block wraps every AS3 file. Think of it as the return address on an envelope nobody reads until something goes wrong. The class that extends Sprite is your document class, the single object Flash instantiates when the movie loads. Sprite is a MovieClip that skipped the timeline and went straight to work, which makes it the right tool roughly always.
The constructor runs exactly once, on load. There is no main(), no window onload, no starting gun. The class simply wakes up and the constructor is the first thing it says. Everything you want on screen has to happen from here or from something here calls.
Now the part that ends careers. A TextField is not a string. It is a display object, and creating one changes nothing you can see. The object exists in memory, invisible, sulking, fully configured and completely absent from the screen. It renders only when it joins the display list, the tree of things Flash is currently drawing. That is what addChild does, and it is the whole trick.
Ninety percent of every why is my screen blank has the same answer, and the answer is a missing addChild. Print this out. Tape it near the monitor. Compile the code above and five words appear in the top left corner, underwhelming on purpose. You now own the display list, which is more than most people who have used Flash for years can honestly say.