Skip to Main Content
Essential ActionScript 3.0
book

Essential ActionScript 3.0

by Colin Moock
June 2007
Intermediate to advanced content levelIntermediate to advanced
948 pages
27h 2m
English
O'Reilly Media, Inc.
Content preview from Essential ActionScript 3.0

Chapter 24. Programmatic Animation

This chapter discusses the basic techniques for creating animation with ActionScript. It focuses on integrating animation code with the Flash runtime’s automatic screen updates. It does not, however, cover advanced animation topics, such as programming physics-based motion, motion on a path, collision detection, bitmap animation effects, or color transformations.

No Loops

To create animation with ActionScript, we change visual content repeatedly over time, producing the illusion of movement. For example, to animate a TextField object horizontally across the screen, we would repeatedly increase, or decrease, its instance variable x. In some programming languages, the natural mechanism for repeatedly altering an instance variable is a loop statement. Consequently, programmers who are new to ActionScript might expect to create animation using a while loop, such as the one shown in the following code:

public class TextAnimation extends Sprite {
  public function TextAnimation () {
    // Create a TextField
    var t:TextField = new TextField();
    t.text          = "Hello";
    t.autoSize      = TextFieldAutoSize.LEFT;
    addChild(t);

    // Update the TextField's horizontal position repeatedly, and stop
    // when it reaches x-coordinate 300
    while (t.x <= 300) {
      t.x += 10;
    }
  }
}

The preceding while loop increments a TextField object’s instance variable x repeatedly, but as an attempt to produce animation it has a fatal flaw: each time the body of the loop executes, the screen is not updated. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Essential ActionScript 2.0

Essential ActionScript 2.0

Colin Moock
The ActionScript 3.0 Quick Reference Guide

The ActionScript 3.0 Quick Reference Guide

Jen deHaan, David Stiller, Darren Richardson, Rich Shupe
ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott, Darron Schall, Keith Peters

Publisher Resources

ISBN: 0596526946Errata