ActionScript 3.0 Quick Reference Guide excerpts: Copy motion, display list, events, and migration


If you're ready to give your development projects a considerable performance boost, learning ActionScript 3.0 is a must. Written by Flash insiders with extensive knowledge of the technology, ActionScript 3.0 Quick Reference Guide for Developers and Designers Using Flash CS4 Professional is designed specifically to help Flash designers and developers make the leap from ActionScript 2.0 to the object-oriented ActionScript 3.0 quickly and painlessly.

When ActionScript 3.0 hit the streets, the reaction from the Flash crowd was enormous, and not without a tremor of intimidation. Certain questions have emerged—on the forums, in classrooms, user groups, and at conferences—more often than others. This book answers the questions we most often encounter, questions that seem to pose the biggest stumbling blocks for longtime users.

ActionScript 3.0 is a huge upgrade to the programming language of Flash—and this guide helps you upgrade your skills to match it. You'll learn key differences between the two language versions, allowing you to more easily leverage ActionScript 3.0 using Flash CS4 Professional and other technologies like Adobe Flex and Adobe AIR.

The first half of the book is something like a fireside chat, providing fairly broad coverage of Flash CS4 Professional, and select overviews of ActionScript 3.0. The second half presents many focused examples of ActionScript 3.0 syntax in small, digestible chunks. Both halves are chock-full of hands-on demonstrations.

Formatted so you can find any topic easily, ActionScript 3.0 Quick Reference Guide explains:

  • Object-oriented programming (OOP) concepts, such as packages and classes
  • ActionScript 3.0 features and player enhancements that improve performance
  • Workflow differences between ActionScript 2.0 and ActionScript 3.0 including tools, code editing, component sets, and image and font rendering

Included is a "Where did it go?" guide to help you find familiar features in ActionScript 3.0—such as global functions, operators, properties, and statements—and step-by-step "How do I?" solutions for performing tasks with ActionScript 3.0, including input, sound, video, display, events, text, and more.

The printed book is available through most major online and retail bookstores worldwide, and can be read online at Safari Books Online. For more information visit the O'Reilly store.

ActionScript 3.0 Quick Reference Guide for Developers and Designers Using Flash CS4 Professional © 2009 David Stiller and Rich Shupe. Reproduced by permission of O'Reilly Media Inc. All rights reserved.

Copying motion as ActionScript 3.0

Chapter 8 discusses an interesting tool in Flash CS4 Professional that helps bridge the gap between programmed and timeline-based animation. Available from the Timeline panel, the Copy Motion as ActionScript 3.0 feature facilitates collaboration between designers and developers by converting timeline tweens and keyframe settings into ActionScript 3.0 code, and sometimes a flexible XML-based format used by the new Animator class.

Because the ActionScript involved is generated automatically, this feature lets a designer use traditional animation techniques, complete with motion guides and easing, to provide sophisticated motion templates that a developer can harness to program animation for any number of additional objects, even in separate FLA files. Topics addressed include copying motion and applying motion to other objects.

Download the complete chapter:

Chapter 8: Copying Motion as ActionScript 3.0 (PDF, 580K)

Working with the display list

Chapter 13 covers one of the two biggest ActionScript changes in version 3.0: the new display architecture. Topics addressed include choosing which type of display object to use, creating a new display object, adding a display object to the display list, specifying the depth of a display object, finding a display object and removing it from the display list, and more.

Download the complete chapter:

Chapter 13: How Do I Work with the Display List? (PDF, 270K)

Working with events

Chapter 14 covers the second biggest change in ActionScript 3.0: the new event model. Gone are the event handlers of prior versions, such as onRelease or the more antiquated on(release) handler applied directly to symbol instances. The new model makes use exclusively of event listeners.

In simple terms, event listeners are established to monitor for the occurrence of a particular event, and then execute a function when that event is received. Since listeners are required for all event processing, this chapter both explains and uses them extensively. Even if you have experience with event listeners from prior versions of ActionScript (perhaps from use with components or objects for capturing key events), the event flow is quite different in ActionScript 3.0. Events can cascade down through the display list and bubble back up to the root of the file, allowing for advanced event handling. In line with the focus of this quick answer guide, this chapter covers the basic essentials of event processing, but provides an adequate overview to get you started.

Download the complete chapter:

Chapter 14: How Do I Work with Events? (PDF, 330K)

Sample migration from ActionScript 2.0 to 3.0

Chapter 18 walks you through a small-scale, manufactured example of a migration from ActionScript 2.0 to ActionScript 3.0. Instead of demonstrating real-world best practices at work, this example is significantly constrained and attempts to insert as many migration issues as possible into its tiny footprint. Throughout the simple particle system example, what may appear to be odd choices, poorly optimized code, or even mistakes have been intentionally injected into the code to either set up a migration task or bring the two versions into a parallel structure.

Download the complete chapter:

Chapter 18: A Sample Migration (PDF, 300K)