Preface

ActionScript 3.0 introduced Flash developers to a new realm. In this improved territory, ActionScript has emerged from the gym with a new physique. The language is more powerful, more efficient, and—thanks to a new internal consistency—easier to learn for those new to the Flash Platform. As the saying goes, change is a good thing. On the other hand, too much of anything can be, well, nerve-wracking. For many, ActionScript’s change equates to a chronic attack of growing pains. Others, used to the paradigms and occasional quirks of ActionScript 2.0, find the new ActionScript 3.0 practically unrecognizable.

In any case, the ongoing support for ActionScript 1.0 and 2.0, in both the Flash authoring environment and Flash Player, means that learning ActionScript 3.0 is, for the immediate future, still an option. For now, you can choose when to learn the new version of the language (and to what degree), applying your newly earned knowledge on a project-by-project basis, if you want. Sometimes, it’ll be easier to decide when to use ActionScript 3.0 than to decide whether you should migrate existing code or start from scratch. For example, if you want significant performance gains, or to use a new feature specific to ActionScript 3.0, using the new language may be a foregone conclusion. How to arrive at completed ActionScript 3.0 code, however, is another question, and that’s where this book is useful.

This book aims to show you where Flash CS4 Professional and ActionScript 3.0 differ from prior releases of Flash and ActionScript, respectively. You can use this text as a guide, helping you decide if new application features warrant an upgrade, and assisting with the steeper learning curve imposed by the more robust new language. Perhaps most importantly, this book will increase your familiarity with ActionScript 3.0 structure and syntax, letting you adjust (or abandon) ActionScript 2.0 coding practices more easily.

What Sets This Book Apart

Simple: Essentially, we’ve created two books in one. Or put another way, there are two sections to the book, each using its own learning methodology.

Part I and Part II are written in classic tech-book formatting and prose. General concepts are introduced and followed with expository prose and simple, demonstrative tutorials as necessary.

Part III and Part IV (especially Part III) are pure reference sections, designed for you to quickly look up and learn from “How Do I...?” scenarios.

Think of the book as a seminar. The first half is presentation; the latter half is Q&A.

What’s in This Book

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. The book’s in a hybrid format to serve two needs. 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. Ideally, you can hop between the two, and gear up or down to the pace that best suits your needs at the time. Navigate the Table of Contents and/or Index to find quick answers to specific questions about ActionScript 3.0 and its application.

Part I: Introduction to ActionScript 3.0

Part I of the text introduces a variety of tools to write ActionScript 3.0, while relying on Flash CS4 Professional as its primary authoring environment. It then discusses some of the attributes that make ActionScript 3.0 stand head and shoulders above its predecessors. Topics include power and performance, the benefits of strong data typing (including robust compile time warnings and error messages) and how the new language architecture can improve your workflow.

Chapter 1, Introducing ActionScript 3.0

Chapter 2, Discovering What You Need to Work with ActionScript 3.0

Chapter 3, Looking at the Changes in ActionScript 3.0

Chapter 4, Exploring the Benefits of Using ActionScript 3.0

Part II: ActionScript and the Flash CS4 Authoring Tool

Part II walks you through the Flash CS4 authoring tool with keen attention to ActionScript-related interface elements, and helps you decide when to use the timeline, and when to use classes, for coding. It also discusses the creation of assets at runtime, how to convert timeline animation into ActionScript (for manipulation and reuse), how to use, skin, and style user interface components, and how to troubleshoot your code when things go awry.

Chapter 5, Creating and Working with Code

Chapter 6, Creating a Document Class

Chapter 7, Working with Library and Linkage Changes

Chapter 8, Copying Motion as ActionScript 3.0

Chapter 9, Using ActionScript 3.0 Components

Chapter 10, Making Up for a Reduced Component Set

Chapter 11, Debugging and Troubleshooting

Part III: How Do I?

Part III switches to cookbook-style—a concise look at a problem, solution, and discussion for each of several issues. This format lets you hone in on syntax and methodology in easily digestible recipes. It starts off by highlighting the Graphics class, formerly the Drawing API, which the second half of the book uses extensively for highly portable, code-only examples. It then discusses the most significant changes introduced by ActionScript 3.0: the new display architecture and event model. Next, you’ll discover new ways of using text for display and interactivity. Finally, you’ll concentrate on input/output processes, including sending and loading XML and variables, as well as loading images, external SWFs, sound, and video.

Chapter 12, How Do I Draw with Code?

Chapter 13, How Do I Work with the Display List?

Chapter 14, How Do I Work with Events?

Chapter 15, How Do I Work with Text?

Chapter 16, How Do I Work with XML?

Chapter 17, How Do I Work with External Assets?

Part IV: Migration

Part IV distills everything covered in Part I through Part III, and applies those skills to the issue of migration—updating existing projects written in ActionScript 2.0 to use ActionScript 3.0 code. This concept’s first application is the migration of a simple particle system. The exercise highlights as many migration issues as possible in a short example, and helps you ask an important question related to your own projects: should you migrate or rewrite? The final chapter of the book serves as a cross-reference, and a code-comparison guide. Specific migration issues are demonstrated in quick syntax examples, comparing ActionScript 2.0 and 3.0 uses. Where applicable, references to more complete discussions elsewhere in the book are included, and select new material in the same comparative format is also added.

Chapter 18, A Sample Migration

Chapter 19, Where Did It Go?

What’s Not in This Book

Due to the size and focus constraints of this book, many aspects of ActionScript usage are necessarily excluded. First and foremost, this book focuses specifically on Flash CS4 Professional, although most of the examples work just fine in Flash CS3. The Flash Platform has grown considerably, so if you prefer other ActionScript coding environments, including Flex Builder, FDT, or FlashDevelop (or even text editors, such as Notepad or TextMate, in conjunction with the Flex SDK command-line compiler), you may want to skim through several of the examples to see if you think they’ll be helpful. In general, you can easily adapt most of the book’s examples for ActionScript 3.0 projects written in other tools, and you are introduced to a handful of those tools in Chapter 2. However, very little additional material, such as Flex Builder MXML documents or project files, is supplied. This book is a migration reference for Flash professionals, so you’ll see mostly FLA and AS files.

Secondly, this book is aimed at relatively experienced ActionScript 2.0 coders who are making the move to ActionScript 3.0. It neither provides language essentials nor serves as a comprehensive reference. As such, if you’re not already comfortable with ActionScript, and want to focus a bit more on fundamentals, you should seek out Learning ActionScript 3.0: A Beginner’s Guide by Rich Shupe and Zevan Rosser (O’Reilly, 978-0-596-52787-7). Conversely, if you’re looking for more of an in-depth reference book, you may prefer Essential ActionScript 3.0 by Colin Moock (O’Reilly, 978-0-596-52694-8).

Finally, while it hits many of the high points, this volume doesn’t cover all areas of ActionScript 3.0 interest, and may not satisfy advanced users’ needs. If you want to immerse yourself in the more elaborate capabilities of the language, you can either acquire the aforementioned Essential ActionScript 3.0 for broad coverage, or look into additional specialized books such as ActionScript 3.0 Design Patterns: Object Oriented Programming Techniques by William Sanders and Chandima Cumaranatunge (O’Reilly, 978-0-596-52846-1) for OOP and design patterns expertise.

Conventions Used in This Book

This book uses the following typographical conventions:

Menu options

Menu options are shown using the → character, such as File→Open.

Italic

Indicates new terms, URLs, email addresses, file names, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that the user should type literally.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Note

This is a note. It contains useful information about the topic at hand, often highlighting important concepts or best practices.

Warning

This is a warning. It helps you solve and avoid annoying problems. Ignore at your own peril.

This Book’s Example Files

You can download the example files for this book at:

http://www.oreilly.com/catalog/9780596517359

Note that, although alternative development platforms are discussed briefly, the examples in this book are presented in the context of classes or timeline frame scripts intended for use with the Flash authoring tool. Self-contained examples are typically intended for inclusion in FLA files or as Flash document classes, but you can adapt them for use in other environments (such as Flex Builder) without support for those tools.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You don’t need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book doesn’t require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code doesn’t require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but don’t require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “The ActionScript 3.0 Quick Reference Guide: For Developers and Designers Using Flash CS4 Professional” by David Stiller, Rich Shupe, Jen deHaan, and Darren Richardson Copyright © 2009 David Stiller and Rich Shupe, 978-0-596-51735-9.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online

Note

When you see a Safari® Books Online icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can find this page at:

http://oreilly.com/catalog/ 9780596517359

Acknowledgments

From David

Thanks to Rich, Jen, Darren, and the gang at O’Reilly. We took a trip to Oz and had enough adventures to write a book about it! (Rich, you owe me a face-to-face sit-down with Pentago!) For technical assistance and encouragement, I’d like to extend gratitude to Marisa Bozza, Tink (Stephen Downs), Greg Dove, Chris Georgenes, Tom Green, Branden Hall, Keenan Keeling, San Khong, John Mayhew, Colin Moock, Robert Penner, Nivesh Rajbhandari, Robert Reinhardt, Steve Schelter, and Kenneth J. Toley. Thanks and love to my #1 woman, Dawn, who introduced me to Georges Méliès, and my #1 girl, Meridian, für unser Abenteur mit Andersen und den Brüdern Grimm.

From Rich

Thanks to David, Jen, and Darren for making me part of the team. Thanks to Robyn Thomas, Michele Filshie, Steve Weiss, and Dennis Fitzgerald for working with me again. You’re unmatched in my professional experience. Thanks to our tech editors Matthew Woodruff, Eric Kramer, and Anselm Bradford. Thanks to Marisa Bozza, Lee Brimelow, John Dowdell, Richard Galvan, Mally Gardner, Stefan Gruenwedel, Jeff Kamarer, Vishal Khandpur, San Khong, John Mayhew, Tony Mowatt, John Nack, Chris Nuuja, Ted Patrick, Nivesh Ragbhandari, and Adobe. Special thanks to my staff at FMA and Mike Wills, and my family for endless support. Last but not least, extra special thanks go to Jodi, Sally, and Claire for everything.

Get The ActionScript 3.0 Quick Reference Guide 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.