Chapter 11. Programmatic Animation

Introduction

Animation can be defined as any visual change over time. If an image does not change over a period of time, it’s impossible to tell whether it is a still image or an animation. There are a variety of properties you can manipulate to produce change, and thus animation. The most obvious is changing an object’s position to make it move. You can also change its size, shape, rotation, transparency or color, to name a few. As long as something changes visually, the viewer never sees the animation.

In the earliest versions of Flash, most animation was done by using tweens. An object was placed on a keyframe, another keyframe was made, and the object was changed in some way. Flash filled in the frames in between, hence, the term tween. Using ActionScript, you can create much more dynamic and interactive animation.

As for what you can animate, a movie clip or sprite is usually a good answer. These objects can contain graphics, and they can have methods and properties that allow them to be moved, scaled, rotated, and otherwise transformed any way you see fit. A movie clip would normally be used only in the Flash authoring environment, where additional frames are added, as in a tween.

Finally, you need some way of getting the changes to occur over time. Your best bet is either an enterFrame handler or a timer. ActionScript statements can be used to make changes to the animated object’s properties on each frame, or timer cycle, if you’re using ...

Get ActionScript 3.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.