Learning ActionScript 3 excerpts: OOP overview, display list, and programmatic motion

Rich Shupe
Rich Shupe
23 June 2008
ActionScript 3 represents a significant change for many Flash users, and a steeper learning curve for the uninitiated. To make learning easy for you and to demonstrate how you can use the Flash language for practical, everyday projects, Rich Shupe and Zevan Rosser share their knowledge in Learning ActionScript 3.
If you are new to the language, follow this hands-on book to learn how ActionScript and Flash work together. You'll get a clear look into essential topics such as logic, event handling, displaying content, classes, and migrating legacy projects to ActionScript 3. The first few chapters expand your skill set by taking you through a variety of scripting scenarios and focusing on clear, concise examples in the Flash Timeline that do not draw heavily on prior knowledge of object-oriented programming (OOP). As the chapters progress, the book gradually introduces more and more OOP techniques, allowing you to choose which scripting approach you prefer.
If you are already comfortable with OOP, refer to the companion website for all the exercises in the book, as well as short quizzes to make sure you're up to speed with key concepts. Topics in Learning ActionScript 3 also include:
  • New ways to harness the power and performance of ActionScript 3
  • Common mistakes that people make with the language
  • Essential coverage of text, sound, video, XML, and drawing with code
  • Migration issues from ActionScript 1 and ActionScript 2 to ActionScript 3
  • Simultaneous development of procedural and object-oriented techniques
  • Tips that go beyond simple script collections, including how to approach a project and which resources can help you along the way
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.
Learning ActionScript 3 © 2008 Rich Shupe. Reproduced by permission of O'Reilly Media Inc. All rights reserved.
ActionScript overview
Chapter 1 covers basic information on ActionScript 3, the Flash platform, procedural versus OOP, the Document class, and legacy code compatibility. It provides a brief overview of ActionScript development, giving you some insight into its use—particularly related to Flash Player and how it handles different versions of ActionScript. It tells you how this version of ActionScript is handled separately from its previous versions at runtime, yet explains how the fundamentals of the language are the same throughout.
The chapter also provides answers to questions like why moving to ActionScript 3 doesn't require you to become an expert at OOP and how Flash CS3 offers a simpler entrance to an OOP application by way of the Document class. Finally, the section on legacy code compatibility briefly introduces the issues involved in developing projects on ActionScript 3 that support older code.
Download the complete chapter:


The display list
Chapter 4 explores the properties of the newly introduced display list in ActionScript 3. One of the most dramatic changes for those designers accustomed to prior versions of ActionScript is the way in which visual elements are added to an application at runtime. ActionScript 3 brings with it an entirely new way of handling visual assets. The display list is a hierarchical list of all visual elements in your file. This chapter introduces you to different objects that can be part of the display list, and helps you grasp the simple difference between display objects and display object containers. It also provides information on manipulating existing members of the display list, adding and removing objects from the list, and changing the hierarchy of assets. The concluding section shows you how to dynamically generate a very simple navigation bar.
Download the complete chapter:


Chapter 7 takes an in-depth look at programming motion in ActionScript 3. Because motion can cover a large number of concepts, the book focuses on only a few—offering simplified simulations in each area and presenting approaches that are simple enough to integrate into your projects with ease.
You begin with simplified movement before learning how to determine the distance between two objects, and then how to animate objects in a circular path and point objects at a specific location. You also learn how to add realism to animations by simulating friction, elasticity, and gravity.
In the section on programmatic tweening, you will read about the Tween class and its occasional partner, the Easing package. The new Animator class in ActionScript 3 can read the XML that you export from timeline tweens and recreate that animation with ActionScript. You will create a simple player for displaying such an animation.
The chapter ends with an applied example of creating a simple particle, covering much of what has been discussed in the chapter.
Download the complete chapter: