ActionScript 1.0 code lives on timelines and mostly works on them. A Flash movie is a
main timeline of frames played at a fixed rate; a movie clip is a symbol with a timeline
of its own, placed as instances on other timelines and nested to any depth. Each clip
is an object of type "movieclip", reached by its instance name.
Frames, labels and scenes
- A timeline plays from frame 1 and loops at the end unless a script calls
stop(). Frames are numbered from 1. - A frame script runs once each time the playhead enters that frame.
- A frame can carry a label, used in place of its number:
gotoAndStop("results"). - Scenes divide the main timeline in the authoring program. In the SWF file they
are joined into one timeline;
gotoAndPlay("Scene 2", 1)works only on the main timeline.
| Method | Does |
|---|---|
play(), stop() | Start and stop the playhead. |
gotoAndPlay(frame), gotoAndStop(frame) | Go to a frame number or label, and play or stop. |
nextFrame(), prevFrame() | Step one frame and stop. |
nextScene(), prevScene() | Go to frame 1 of the next or previous scene (global functions, main timeline only). |
Properties
Flash’s own properties of a clip start with an underscore. They can be read and set
directly, or with the Flash 4 functions getProperty(clip, _x) and
setProperty(clip, _x, value).
| Property | Is | Access |
|---|---|---|
_x, _y | Position of the clip’s registration point in its parent, in pixels | read, write |
_xscale, _yscale | Scale in per cent; 100 is the symbol’s size | read, write |
_width, _height | Size of its contents in its parent’s space, in pixels | read, write |
_rotation | Rotation in degrees, clockwise | read, write |
_alpha | Opacity in per cent, 0 to 100 | read, write |
_visible | Whether it is drawn; hidden clips do not take mouse events | read, write |
_name | Its instance name | read, write |
_currentframe, _totalframes, _framesloaded | The playhead’s frame, the number of frames and how many have downloaded | read |
_target | Its path in slash syntax | read |
_url | The URL of the SWF file it came from | read |
_droptarget | The path of the clip it was last dropped on, after a drag | read |
_xmouse, _ymouse | The pointer’s position in the clip’s own space (Flash 5) | read |
_parent | The containing clip | read |
_quality, _highquality, _focusrect, _soundbuftime | Movie-wide settings: rendering quality, the old quality switch, the focus rectangle, and seconds of streaming sound to buffer | read, write |
Flash MX adds enabled, useHandCursor, hitArea,
trackAsMenu, focusEnabled, tabEnabled,
tabIndex and tabChildren.
Depths and levels
Every clip on a timeline sits at a depth; higher depths are drawn in front, and one
depth holds one clip. Clips placed in the authoring program take depths from −16383
upwards. Clips made by script use depths from 0 to 1048575; depths from −16383 to −1
are left to the authoring program, and −16384 puts a clip behind all of them.
removeMovieClip does not remove a clip at a negative depth, so a placed
clip has to be moved with swapDepths first.
Above the main timeline are levels: loadMovieNum("menu.swf", 1) loads a
movie into _level1, drawn over _level0. Each level has its
own _root. Loading into level 0 replaces the whole movie.
Making and removing clips
| Call | Does | Player |
|---|---|---|
duplicateMovieClip(clip, newName, depth) | Copies a clip on the same timeline. Also a method, clip.duplicateMovieClip(newName, depth). | 4 |
clip.attachMovie(linkageName, newName, depth) | Places a new instance of a library symbol inside clip. The symbol must have a linkage name and be exported for ActionScript. Flash MX adds a fourth argument, an object whose properties are copied to the new clip, and returns the new clip. | 5 |
clip.createEmptyMovieClip(newName, depth) | Makes an empty clip, for drawing or loading into. | 6 |
clip.createTextField(newName, depth, x, y, width, height) | Makes a text field. | 6 |
removeMovieClip(clip), clip.removeMovieClip() | Removes a clip made by script or at a positive depth. | 4, 5 |
clip.swapDepths(depthOrClip) | Moves a clip to a depth, swapping with any clip there. | 5 |
clip.getDepth() | Gives its depth. | 6 |
Loading movies and images
loadMovie(url, clip)orclip.loadMovie(url)replaces a clip’s contents with an external SWF file, and from Flash Player 6 with a JPEG image. The clip keeps its name, position and other properties, but loses its variables and handler properties.loadMovieNum(url, level)loads into a level.unloadMovieandunloadMovieNumempty them again.getBytesLoaded()andgetBytesTotal()(Flash 5) and_framesloadedshow progress, for preloaders.
Dragging, hit tests and coordinates
| Method | Does |
|---|---|
startDrag(lockCentre, left, top, right, bottom), stopDrag() | Makes the clip follow the pointer, optionally inside a rectangle. One clip can be dragged at a time. |
hitTest(x, y, shapeFlag) | True if the point, in stage coordinates, is inside the clip’s bounding box, or with shapeFlag true inside its actual shape. |
hitTest(otherClip) | True if the two clips’ bounding boxes overlap. |
getBounds(targetClip) | An object with xMin, xMax, yMin, yMax in another clip’s coordinates. |
localToGlobal(point), globalToLocal(point) | Convert an object with x and y between the clip’s space and the stage’s. |
setMask(clip) | Uses another clip as a mask (Flash MX). |
The drawing API (Flash MX)
From Flash Player 6 a clip can draw vector shapes into itself. The drawing sits
behind the clip’s other contents and is kept until clear().
| Method | Does |
|---|---|
lineStyle(thickness, rgb, alpha) | Sets the line for the following segments; no arguments means no line. |
beginFill(rgb, alpha) | Starts a filled shape. |
beginGradientFill(type, colours, alphas, ratios, matrix) | Starts a "linear" or "radial" gradient fill. |
moveTo(x, y) | Moves the pen without drawing. |
lineTo(x, y) | Draws a straight line. |
curveTo(controlX, controlY, x, y) | Draws a quadratic Bézier curve. |
endFill() | Closes and fills the shape. |
clear() | Removes everything drawn. |
this.createEmptyMovieClip("box", 1);
box.lineStyle(2, 0x333333, 100);
box.beginFill(0xFFCC00, 100);
box.moveTo(0, 0);
box.lineTo(100, 0);
box.lineTo(100, 60);
box.curveTo(50, 90, 0, 60);
box.endFill();
box._x = 40;