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. HTML5 Canvas documents' JavaScript plays there too.

No code needed

To make a character or a menu answer clicks and keys without writing ActionScript, use the States panel: frame labels become states, and arrows between them say what sends the playhead from one to another. Phoenix writes the script for you.

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. File › Publish compiles the same classes into the SWF movie (see SWF movies), and translates them to JavaScript for an HTML5 page, so the movie's scripts, its classes and its components run in any browser (see HTML5 pages).

Published movies

An SWF movie opened in Phoenix keeps the ActionScript 3 compiled into it, and Test Movie runs it: the main timeline is an instance of the movie's own main timeline class, each symbol linked to a class is that class, and the frame scripts are the ones that class gives its frames. The classes compiled into the movie come first, so a movie built with the components runs its own copies of them rather than Phoenix's. A movie that loads shared libraries before it starts (a preloader for text layout framework text) plays the movie it would load.

A movie published with ActionScript 1 or 2 keeps that compiled too, and Test Movie and Phoenix play run it as a player would: each frame's actions when the frame is reached, a symbol's #initclip actions before the frame that first needs it, buttons' on() handlers (key presses among them) and movie clips' onClipEvent() handlers. The frames that had scripts carry a comment saying so, as the code cannot be turned back into source. Prototypes, Object.registerClass, ActionScript 2 classes, onEnterFrame, setInterval and the oldest actions (tellTarget, slash paths such as /hat:size, getProperty) all run; names are found whatever their case in movies published for player 6 and before, as they were then. Loading other movies and variables (loadMovie, loadVariables) is not done.

HTML5 Canvas JavaScript

An HTML5 Canvas document's scripts are JavaScript, written for CreateJS, the library its published web page plays with. Make one with File › New, choosing HTML5 Canvas as the Platform; a Canvas document made elsewhere opens as one, and keeps its publish settings when saved. The Actions panel edits and checks its scripts as JavaScript, with JavaScript snippets, the Document Info in the Properties panel shows its Platform, and Test Movie runs it:

A cached object is drawn as it is, not as it was when cached, so updateCache() is not needed to show changes, and drawing over a cache (updateCache("source-over")) is not there yet; text drawn as an outline is filled, and dashed lines are solid. What Test Movie does not have yet, such as createjs.DOMElement, drawing to a canvas's context, or another compositeOperation, says so in the Output panel when a script asks for it: that script stops there, and the movie plays on. A script that runs for more than five seconds (a loop that never ends) is stopped the same way.

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 their ActionScript compiled, ActionScript 3 with the same classes Test Movie loads (see SWF movies).