Quick Start Guide to Programming in ActionScript 3

summary

Table of Contents

01 Download the Free SDK
02 Bookmark the Language Reference
03 Set Up Your Favorite Log Viewer and mm.cfg
04 Write Hello World
05 Compile with mxmlc and fcsh
06 View With the Debug Player
  References
 


Download the Free SDK

Head over to Adobe and grab whatever is current and stable. The build called 'Adobe Flex SDK' has the SDK and runtimes all together in one download. There's no install to perform, just unzip the SDK wherever you'd like it to be. Add the bin/ folder to your path.

 


Bookmark the Language Reference

This is the dictionary of native and extension classes provided by the runtime and SDK frameworks. Unless you are interested in Flex or/and Air development, you can ignore everything that is not in the flash.* package or top-level or global.

You'll eventually want to memorize most of the reference and recite it to your pillow at night, but for starters you should probably focus on Sprite, Shape, Bitmap, TextField and Loader and the classes they reference.

 


Set Up Your Favorite Log Viewer and mm.cfg

Vizzy is recommended because it's free, simple, it works and it's cross-platform. It also creates the mm.cfg file for you if you haven't already, which is nice.

 


Write Hello World

Your main class must extend Sprite or a subclass of Sprite, e.g. MovieClip or MySuperSpriteExtension. Here's something simple that traces hello and your flash player version:

// mxmlc Main.as -output=hello.swf -default-size=800,600 -default-frame-rate=30 -default-background-color=0x00ff00 package { import flash.display.Sprite; import flash.system.Capabilities; public class Main extends Sprite { public function Main() { super(); trace("hello tracelog, i am version " +Capabilities.version); } } }

Main.as
 


Compile with mxmlc and fcsh

With the SDK bin/ folder in your path, you can open a command prompt, change to the directory your saved Main.as into, and minimally type: mxmlc Main.as
This will compile Main.as to Main.swf.

Type: mxmlc -help list advanced details to see the full set of compiler options.
Typically you're interested in:

Flex Compiler Shell

Also in the bin/ folder is an app called fcsh. You start it up and it stays open and proxies calls to mxmlc for you so you don't have to incur the cost of the jvm initializing up every time you compile with mxmlc or compc.

For example: > fcsh starts up the shell
(fcsh) mxmlc Main.as caches a call to mxmlc and assigns an id number to it
(fcsh) compile 1 requests the call cached as id 1 to be run again

Oddly, you type quit to exit the shell, not exit.

 


View With the Debug Player

Open your new swf with a debug version of the Flash player: either one installed in your web browser, or a stand-alone app from the runtimes/player/ SDK folder. Verify the player is a debug version by right-clicking anywhere in the player window and looking for the word 'Debugger' in the context menu. It doesn't matter if the word is greyed out.

Trace calls are only written to log when you're running in a debug player and you have mm.cfg configured.

The swf itself won't look like much since we didn't add anything graphical to the display list, but if all is set up well, you should be able to open Vizzy or your log viewer of choice pointed at flashlog.txt and see our "hello tracelog" message.

Next, try adding some things to look at.


 


References