19 February 2007
Well before Ajax and Microsoft Windows Presentation Foundation, Macromedia Flash provided the first method for building "rich" web pages. Now that Flash is a full-fledged development environment, learning ActionScript 3 is key—a challenge for even the most experienced Flash developer.
The following book excerpts include Chapters 1, 2, 3, 5, and 6 from ActionScript 3 Cookbook by Joey Lott, Darron Schall, and Keith Peters, published by O'Reilly Media. This book offers more than 300 solutions to solve a wide range of coding dilemmas so you can learn to work with the new version right away.
This book is written with all levels of ActionScript developers in mind—people like you who want practical solutions to common problems. It contains many accessible and practical examples, solutions, and insights into the situations that Flash and ActionScript developers are sure to encounter. Each recipe presents a problem, a solution, and a discussion of the solution. You can quickly locate the recipe that most closely matches your situation and get the solution without having to read the whole book to understand the underlying code. The book helps you understand the concepts by applying them in real situations. You'll even learn how to link modular ActionScript pieces together to create rock-solid solutions for Flex 2 and Flash applications.
ActionScript 3 Cookbook © 2006 Joey Lott, Darron Schall, and Keith Peters. Reproduced by permission of O'Reilly Media Inc. All rights reserved.
Chapter 1 covers basic programming tasks such as using looping statements, timers, and more. It discusses the frequent goals and problems that relate to core usage. These recipes can help you handle situations that arise in every ActionScript 3 project. This chapter includes instructions on getting started with Flex Builder 2, setting up an ActionScript project, and writing code for your first application. It provides a useful glossary of terms and includes information on how to trace messages, handle events, and perform actions conditionally as well as outlining best practices for creating reusable code.
Chapter 2 dives into writing custom classes with ActionScript 3. The core focus of ActionScript 3 is using classes as building blocks. You can create packages to organize your custom classes into groups. When using Flex 2, all ActionScript code is placed within a class. This chapter provides invaluable information about how to name and save your custom classes, as well as creating subclasses, methods, and properties. It also covers how to dispatch events. Learning how to create custom classes is integral to ActionScript 3—and it's the next big step to expanding your application development skills.
Chapter 3 takes an in-depth look at the runtime environment in Flash Player 9. This chapter covers how to get information about the operating system, device, and Flash Player version in use, as well as discussing important security functions. Ensure that your application appears as expected by programmatically detecting display settings and scaling the content. Change alignment of the SWF, determine the user's audio and video playback capabilities, and even prompt the user to change their Flash Player settings. This chapter also includes information related to loading external content into your application from another domain.
Chapter 5 discusses working with indexed collections of data, called arrays. Every aspect of using arrays is covered, from adding and removing elements to sorting. Arrays are very powerful and allow you to group related data together, which can then be accessed and displayed within your application when desired. This chapter describes both associative and integer-indexed arrays. ActionScript even allows you to store different data types in a single array—unlike other programming languages. This chapter can help you get started using arrays, including looping through an array, searching for matching elements, randomizing the elements in an array, and implementing custom sorting of data.
Chapter 6 describes the new rendering model for ActionScript 3 and Flash Player 9—which differs radically from the previous versions. This chapter focuses on using display objects to control the visual data shown on the screen. The new rendering model is still hierarchical, but is much more flexible and uses the display list concept and the classes available in the flash.display package. Each SWF now contains one display list, which is comprised of three types of elements: the Stage, display object containers, and display objects. Transitioning to the display list offers many benefits for developers, including increased performance, easier depth management, and less rigid structure. It also provides a much simpler process for creating visual items programmatically.