Quick Start Guide to Programming in ActionScript 3
summary
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:
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:
- -output
- -default-size
- -default-frame-rate
- -default-background-color
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
- Related Links
- free Flex SDK: http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK
- as3 language reference: http://www.adobe.com/go/AS3LR
- Vizzy: http://code.google.com/p/flash-tracer/
- mm.cfg: http://livedocs.adobe.com/flex/3/html/help.html?content=logging_04.html
- simple as3 examples: http://edutechwiki.unige.ch/en/AS3_simple_examples
- beginner's guide to as3: http://www.senocular.com/flash/tutorials/as3withmxmlc/
- as3 tips and tricks: http://www.kirupa.com/forum/showthread.php?t=223798