Fundamentals of ActionScript 3.0
Develop and Design
Doug Winnie
Fundamentals of ActionScript 3.0: Develop and Design
Doug Winnie
Peachpit Press
1249 Eighth Street
Berkeley, CA 94710
510/524-2178
510/524-2221 (fax)
Find us on the Web at: www.peachpit.com
To report errors, please send a note to
Peachpit Press is a division of Pearson Education
Copyright 2012 by R. Douglas Winnie
Editor: Nancy Peterson
Production editor: Myrna Vladic
Development editor: Robyn G. Thomas
Copyeditor: Liz Merfeld
Technical Editor: Christopher Coudron
Cover design: Aren Straiger
Cover production: Mimi Heft
Interior design: Mimi Heft
Compositor: Danielle Foster
Indexer: Jack Lewis
Notice of Rights
All rights reserved. No part of this book may be reproduced or transmitted in any form by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. For information on getting permission for reprints and excerpts, contact .
Notice of Liability
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of the book, neither the author nor Peachpit Press shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the instructions contained in this book or by the computer software and hardware products described in it.
Trademarks
ActionScript and Flash are trademarks of Adobe Systems Inc., registered in the United States and other countries. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Peachpit Press was aware of a trademark claim, the designations appear as requested by the owner of the trademark. All other product names and services identified throughout this book are used in editorial fashion only and for the benefit of such companies with no intention of infringement of the trademark. No such use, or the use of any trade name, is intended to convey endorsement or other affiliation with this book.
ISBN 13: 978-0-321-77702-7
ISBN 10: 0-321-77702-6
9 8 7 6 5 4 3 2 1
Printed and bound in the United States of America
This book is dedicated to Hoover. Hoover was a big part of my life,
and was always by my side while doing tech-no things. I miss you Hoover!
This book is also dedicated to my husband, Mike.
While not always into my tech-no things, he is my inspiration for doing
great thingstech-no or not. Thanks, Groovy Dude!
Acknowledgements
With too many people to mention individually, Im going to do a group acknowledgement of all of the members of the Adobe Flash Professional, Flash Player, AIR, and Flex teams that have inspired me to create great things, and to a platform that overcomes amazing obstacles to give creative and web professionals the ability to express themselves wherever they go.
I also want to acknowledge Chris Coudron, my tech reviewer and friend, for his effort to make me look good in code and for reminding me that there is not a NOR operator in ActionScript. Doh!
Introduction
Welcome to ActionScript. Over the next several chapters, youll be introduced to one of the most versatile programming languages to create web applications for the browser, desktop applications, and mobile apps for multiple platforms. For years the Flash Platform has provided people with the most powerful set of technologies to creatively express themselves across multiple screens and platforms with its combination of the Flash Player and AIR runtimes, tools like Flash Professional CS5.5 and Flash Builder 4.5, and languages and frameworks like ActionScript 3.0 and Flex 4.5.
Over the last several years, I have taught people how to make their projects interactive and how to captivate and engage users. During that time at San Francisco State University, my series on Adobe TV, and conference appearances, I have appreciated the difficulty of learning scripting and coding. Learning programming is a steep task, and there are many ways to teach it. What I have found is that combining programming basics, simple examples, problem solving, and real-world projects has been very effective, and it is what you have in your hands (or on your screen) now.
Who This Book Is For
This book is crafted for people who are familiar with Flash Professional, the animation and interactive design tool from Adobe Systems that is part of Creative Suite. The lessons and projects here assume that you have a basic understanding of the Flash Professional product. This book is designed for people who are new to coding or are struggling with the migration from ActionScript 2.0 to 3.0. Here are some examples of what you should know and be able to do before attempting to start with this book:
Import graphical assets from Creative Suite design tools
Create timeline animations using tweens using keyframes
Create symbols using the Library panel
Organize and rename timelines in the Timeline panel and symbols in the Library panel
Publish and build animations for the web browser
With these basic skills, you can create very interesting web animations; however, without ActionScript, the animations lacked any interaction with the user, and there is no way to bring them to other platforms including mobile devices. That is exactly what this book will teach youhow to make these projects interactive and take them further.
The latest edition, Flash Professional CS5.5, has added a significant number of new features to support mobile app creation that are covered at the end of the book.
Who This Book Is Not For
If you are already an intermediate or advanced coder, this book may be too basic for your needs. There are a significant number of books that focus on advanced ActionScript 3.0 concepts, including the adoption of best practices and code design patterns that will make you a better and more proficient coder.
In addition, if you have never worked with Flash Professional, I recommend you learn how to use the basic product before tackling the contents here. There are excellent books available to help you learn how to get started with Flash Professional to create animations and how to master design workflows when working with Creative Suite design applications like Photoshop, Illustrator, and Fireworks.
How You Will Learn
This book has a specific methodology for how the concepts are introduced. First are the fundamentals of how to interact and work with objects that are on the Stage. The examples that are in the book are simpleand this is intentional, to help you understand how ActionScript works without getting into the weeds of your projects design or assets. You can adapt and expand these simple examples for your own projects.
After you gather a sizable amount of new ActionScript know-how, it is time to put it to work. There are three major projects in the book that pose real-world situations for you to solve using the skills you have learned. The projects present you with a programming challenge and ask you to solve it. You can compare your finished projects with the examples in the book to discover how your approach matches or differs.