Animation

ActionScript and Test Movie

ActionScript is the scripting language of Flash movies and games: buttons that answer clicks, clips that follow the keys, scores kept in text fields. Phoenix writes it in the Actions panel and plays it in Test Movie, ActionScript 1 and 2 as older movies have it and ActionScript 3 frame scripts with their event listeners.

Where scripts go

A script belongs to one of two places:

A keyframe
It runs each time the playhead reaches that frame: on the main timeline, or inside a movie clip as the clip plays. Most scripts go here, and in ActionScript 3 all of them do. A layer named actions at the top of the timeline, with nothing else on it, keeps them easy to find.
A button or movie clip instance
ActionScript 1 and 2 only. A button's script holds handlers such as on (release) { ... }, run when it is clicked; a movie clip's holds onClipEvent (enterFrame) { ... } and the like.

Scripts reach movie clips, buttons and text fields by their instance names, set in the Properties panel: a clip named hat is hat to the script on its timeline. Library symbols are reached by their linkage, set in the library's symbol properties (exported for ActionScript, with an identifier or a class name).

The Actions panel

Window › Actions (F9) shows the script of the keyframe at the playhead on the current layer, ready to type into. Select a button or movie clip instance on the stage instead and it shows that instance's own script.

Writing code

ActionScript files (.as) open in Commands › Script Editor, the same editor in a window of its own; see Write a script.

Test Movie

Control › Test Movie (Ctrl+Enter) plays the movie in a window of its own as Flash Player would, at the document's frame rate, running its ActionScript. It starts at the first scene and plays the scenes in turn, back to the first after the last. Buttons light up under the mouse and answer clicks, and keys typed in the window go to the movie, so an interactive movie, such as a dress-up game, can be played.

Test Movie window playing a dress-up game: a fairy dressed in blonde hair, a blue blouse and skirt and pink tights, with the buttons that chose them on the left

Buttons and movie clips are clicked by their art, so a click between two buttons finds neither. Click an input text field to type into it.

ActionScript 1 and 2

As older movies and games are written, they run as Flash Player runs them:

ActionScript 3

An ActionScript 3 movie (as its publish settings say) plays with the flash.* classes, over the display list: everything on the stage is a display object scripts can find, move, filter, draw into and take apart, and every class can be made with new, extended, and tested with is and instanceof.

Class files

An ActionScript 3 movie can keep its code in class files (.as). Test Movie loads each class the first time a script needs it, by its name: game.Hat is game/Hat.as, looked for in turn in the document's folder, the source paths in its publish settings, the sources kept beside a library the publish settings list (the src folder beside a .swc's lib folder), any src folder in the document's folder or the folders in it, the class paths in Edit › Preferences › ActionScript, and last Phoenix's own classes.

A class that does not compile shows its file and line in the Output panel, as a frame script does.

What games use

In both versions:

Errors and trace

What scripts trace() goes to the Output panel (F2). A script error stops that script only, and is shown in the Output panel, in red, with the frame or button and the line it was on, and in ActionScript 3 the functions it was in; the movie plays on, and the line below the movie counts the errors.

Once the Test Movie window is closed, double-click an error in the Output panel to see its script in the Actions panel with the caret on that line.

To check a movie's scripts without a window, for a whole folder of games say, use Phoenix play on the command line: it plays the movie, prints what its scripts trace and the errors they stop on, and can click every button in turn.

Simple frame actions while animating

Playback on the stage, and exported movies, do not run scripts. With Control › Enable Simple Frame Actions on, they follow the simple calls in frame scripts (stop(), play() and the gotos), which is enough for a pose held or a section repeated; see Frame scripts.

Not yet

Loading other movies (SWF files), video, the microphone and camera, sockets, ByteArray's readObject and writeObject, and the DataGrid, TileList, ScrollPane, UILoader and ProgressBar components. Published SWF files carry the artwork but not the scripts.