Macromedia Flash MX Advanced For Windows and Macintosh: Visual QuickPro Guide Russell Chun Publisher: Peachpit Press First Edition May 08, 2002 ISBN: 0-201-75846-6, 480 pages Ready to take your Flash knowledge to the next level? Then Macromedia Flash MX Advanced for Windows and Macintosh: Visual QuickPro Guide is your ticket. Designed for professionals like yourself-users who have mastered the basics of Flash but need help with the advanced animation techniques and ActionScripting--this guide is a must-have for graphic designers, Web animators, game programmers, interface designers, and multimedia pros. In this volume, veteran Flash instructor Russell Chun eschews "cool effects" and case studies for an approach that emphasizes methodology and problem-solving. Using the task-based format that readers have come to expect from this popular series, Russell has divided the text into three primary sections: animation, navigation, and interactivity. The guide covers all of Flash’s new features, including the revamped user interface, brand-new commands, and added drawing and text tools. Plus, you’ll find plenty of screen shots and visual aids to reinforce the text. With Flash MX Advanced for Windows and Macintosh: Visual QuickPro Guide by your side, you’ll soon find yourself thinking--maybe even dreaming--in Flash. Macromedia Flash MX Advanced For Windows and Macintosh: Visual QuickPro Guide Thank you Introduction Who Should Use This Book Goals of This Book What’s New in Flash MX I: Approaching Advanced Animation 1. Building Complexity Motion-Tweening Strategies Using multiple guided layers Shape-Tweening Strategies Creating Special Effects Animated and Complex Masks 2. Working with Video and 3d Integrating Flash and Video Exporting to QuickTime, QuickTime video, and AVI Rotoscoping Simulating Video Simulating 3D II: Understanding ActionScript 3. Getting a Handle on Actionscript About Objects and Classes About Methods and Properties Writing with Dot Syntax More on Punctuation Using Objects About Functions Using Comments III: Navigating Timelines and Communicating 4. Advanced Buttons and Event Detection Events and Event Handlers The Button Object Invisible Buttons Tweening Buttons Animated Buttons and the Movie-Clip Symbol Complex Buttons Button-Tracking Options Button Properties The Movie Clip As a Button Keyboard Detection Mouse Detection Clip Events Creating Continuous Actions with enterFrame Creating Continuous Actions with setInterval A Summary of Events and Event Handlers 5. Controlling Multiple Timelines Navigating Timelines with Movie Clips Naming Instances Target Paths Absolute and Relative Paths Using the with Action to Target Movie Clips Slash Notation and tellTarget Scope Movie Clips As Containers 6. Managing Outside Communication Communicating Through the Web Browser Working with browser framesets and windows Communicating with External Movies Communicating with External Images Communicating Between Two Movies Using Projectors and the fscommand Action Communicating with the Printer Detecting the Movie’s Playback Environment Detecting Download Progress: Preloaders IV: Transforming Graphics and Sound 7. Controlling the Movie Clip Dragging the Movie Clip Setting the Movie-Clip Properties Getting the Movie-Clip Properties Modifying the Movie-Clip Color Swapping Overlapping Movie Clips Detecting Dropped Movie Clips Detecting Movie-Clip Collisions Getting the Boundaries of Movie Clips Generating Movie Clips Dynamically Removing Movie Clips Dynamically Creating Shapes Dynamically Using Dynamic Masks Customizing Your Pointer Beginning to Animate with ActionScript 8. Controlling Sound Using the Sound Object Attaching Sounds Playing Sounds Modifying Sounds Modifying Independent Sounds Transforming Sounds Creating Dynamic Sound Controls Loading External Sounds Reading Sound Properties Detecting Sound Events V: Working with Information 9. Controlling Information Flow Initializing Information Using Variables and Expressions Loading External Variables Storing and Sharing Information Modifying Variables Concatenating Variables and Dynamic Referencing Testing Information with Conditional Statements Providing Alternatives to Conditions Branching Conditional Statements Combining Conditions with Logical Operators Looping Statements 10. Controlling Text Input Text Dynamic Text Selecting Text-Field Options Concatenating Text Displaying HTML Tweening Text Fields TextField Properties Generating Text Fields Dynamically Modifying Text in Text Fields Manipulating Text-Field Contents The Selection Object Controlling the Focus of Text Fields Controlling the Selection Within Text Fields Detecting Changes in the Text Field The String Object Analyzing Strings Rearranging Strings Modifying Strings 11. Manipulating Information Calculating with the Math Object Calculating Angles with the Math Object Using Sine and Cosine for Directional Movement Calculating Distances with the Math Object Generating Random Numbers Ordering Information with Arrays Keeping Track of Movie Clips with Arrays Using the Date and Time Building Reusable Scripts Building Custom Classes with Functions 12. Managing Content and Troubleshooting Sharing Library Symbols Sharing Fonts Using Components Editing ActionScript Including External ActionScript Using the Movie Explorer Listing Variables and Objects in the Output Window Tracing Variables in the Output Window Debugging Optimizing Your Movie Avoiding Common Mistakes A. Object Methods and Properties Array Object Button Object Color Object Date Object Key Object Math Object Mouse Object Movie Clip Object Selection Object Sound Object Stage Object String Object TextField Object TextFormat B. Keyboard Keys and Matching Key Codes Letters Numbers and Symbols Function Keys C. Summary of the Actions Category Descriptions of Actions D. Summary of Events and Object Associations Summary of Events and Object Associations Peachpit Press 1249 Eighth Street Berkeley, CA 94710 510/524-2178 800/283-9444 510/524-2221 (fax) Published by Peachpit Press, a division of Pearson Education. Find us on the Web at www.peachpit.com. To report errors, please send a note to [email protected]. Published in association with Macromedia Press. © 2002 Russell Chun Editor: Rebecca Gulick Production Coordinator: Lisa Brazieal Copyeditor: Kathy Simpson Additional copyediting: Wendy Katz Technical reviewer: Clint Critchlow, Macromedia Tech Support Additional technical feedback: Erica Norton and Bentley Wolfe of Macromedia, Inc. Compositor: Owen Wolfson Indexer: Emily Glossbrenner Cover design: The Visual Group CD-ROM mastering: Victor Gavenda 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 [email protected]. 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 Visual QuickStart Guide is a registered trademark of Peachpit Press, a division of Pearson Education. Macromedia is a registered trademark, and Macromedia Flash and Flash are trademarks of Macromedia, Inc. Throughout this book trademarked names are used. Rather than put a trademark symbol in every occurrence of a trademarked name, we state that we are using the names in an editorial fashion only and to the benefit of the trademark owner with no intention of infringement of the trademark. 9 8 7 6 5 4 3 2 1 Printed and bound in the United States of America Thank you Many thanks to everyone at Peachpit Press, especially my dedicated editor, Rebecca Gulick, for her support throughout the process and for the polish she put on my words. Thanks also to Lisa Brazieal, Kathy Simpson, Emily Glossbrenner, Owen Wolfson, Victor Gavenda, Marjorie Baer, and Nancy Ruenzel for their tremendous work, and to Gary-Paul Prince and Kim Lombardi for their tireless promotional efforts. Special thanks to Steve Vargas, my fellow Flash instructor, for cheerfully writing the sections on XML and the CGI GET and POST methods and making sense out of these complex topics. Thanks to the technical reviewers at Macromedia: Erica Norton and Bentley Wolfe, for their early review; and Clint Critchlow, for his enthusiasm, careful attention, and helpful suggestions. I’m grateful to the numerous people and friends who lent their time and talents to the video, sound, photos, and illustrations: Eric Stickney, Josh Frost, Ross “Hogg” Viator, Khin Mai Aung, David Harrington, SadSadFun (A. Gass, B. Chulada, F. Parsa, and M. Chulada), Derek Jimenez, and Tim Cramer. Additional images and sound provided courtesy of Benjamin Cummings, Corel Photo, Gary Fisher bikes, Music4Flash.com, RocketClips.com, Kim Steinhaug and SubReal from Flashkit.com, 3DModelz.com, 3DM-MC.com, Help3D.com, and Eden, Jonah, Bennet, David, Alexandra, and Christina Chun and their proud grandpa “Ang-Ang.” Introduction Macromedia Flash MX is one of the hottest technologies on the Web today. Leading corporate Web sites use its streamlined graphics to communicate their brands; major motion picture studios promote theatrical releases with Flash animations; and online gaming and educational sites provide rich user experiences with Flash interactivity. As a vector-based animation and authoring application, Flash is ideal for creating high-impact, low-bandwidth Web sites incorporating animation, text, video, and sound. With robust support for complex interactivity and server-side communication, Flash is increasingly the solution for developing Internet applications as well. From designer to programmer, Flash has become the tool of choice for delivering dynamic content across various browsers and platforms. As the popularity of Flash increases, so does the demand for animators and developers who know how to tap its power. This book is designed to help you meet that challenge. Learn how to build complex animations, integrate sophisticated interfaces and navigation schemes, and dynamically control graphics, video, sound, and text. Experiment with the techniques discussed in this book to create the compelling media that Flash makes possible. It’s not an exaggeration to say that Flash is revolutionizing the Web. This book will help you be a part of that revolution. So boot up your computer and get started. Who Should Use This Book This book is for the designers, animators, and developers who want to take their Flash skills to the next level. You’ve mastered the basics of tweening and are ready to move on to more complex tasks involving video, masking, dynamic sound control, or movie-clip collision detection. You may not be a hard-core programmer, but you’re ready to learn how ActionScript can control graphics, sounds, and text. You’re ready to integrate interactivity with your animations to create arcade-style games, to create complex user-interface elements like pull-down menus, and to learn how Flash communicates with outside applications such as Web browsers. If this description fits you, then this book is right for you. This book explores the advanced features of Flash MX, so you should already be comfortable with the basic tools and commands for creating simple Flash movies. You should know how to create and modify shapes and text with the drawing tools and be able to create symbols. You should also know how to apply motion and shape tweens, and how to work with frame-by-frame animation. You should know your way around the Flash interface: how to move from the Stage to symbol-editing mode to the Timeline, and how to manipulate layers and frames. You should also be familiar with importing and using bitmaps and sounds, and assigning basic actions to frames and buttons for navigation. Review the tutorials that come with the software, or pick up a copy of Macromedia Flash MX: Visual QuickStart Guide by Katherine Ulrich. Goals of This Book The aim of this book is to demonstrate the advanced features of Flash MX through a logical approach, emphasizing how techniques are applied. You will learn how techniques build on each other, and how groups of techniques can be combined to solve a particular problem. Each example you work through puts another skill under your belt, so by the end of this book you’ll be able to create sophisticated interactive Flash projects. For example, creating a pull-down menu illustrates how simple elements— invisible buttons, event handlers, button-tracking options, and movie clips— come together to make more complex behaviors. Examples illustrate the practical application of techniques, and additional tips explain how to apply these techniques in other contexts. How to Use This Book The concepts in this book build on each other, so the material at the end is more complex than that at the beginning. If you’re familiar with some of the material, you can skip around to the subjects that interest you, but you’ll find it most useful to learn the techniques in the order in which they appear. As with other books in the Visual QuickPro Guide series, tasks are presented for you to do as you read about them, so that you can see how a technique is applied. Follow the step-by-step instructions, look at the figures, and try them on your computer. You’ll learn more by doing and by taking an active role in experimenting with these exercises. Tips follow the specific tasks to give you hints on how to use a shortcut, warnings on common mistakes, and suggestions on how the technique can be extended. Occasionally, you’ll see sidebars in gray boxes. Sidebars discuss related matters that are not directly task-oriented. You’ll find interesting and useful concepts that can help you understand how Flash works. What’s in This Book This book is organized into five parts: Part I: Approaching Advanced Animation This part covers advanced techniques for graphics and animation, including strategies for motion tweening, shape tweening, masking, and using digital video and 3D graphics. Part II: Understanding ActionScript This part introduces ActionScript, the scripting language Flash uses to add interactivity to a movie. You’ll learn the basic components of the language and how to use the Actions panel to construct meaningful code. Part III: Navigating Timelines and Communicating This part teaches you the ways in which Flash can respond to input from the viewer and how complex navigation schemes can be created with multiple Timelines. You’ll also see how Flash communicates with external files and applications such as Web browsers. Part IV: Transforming Graphics and Sound This part demonstrates how to dynamically control the basic elements of any Flash movie—its graphics and sound— through ActionScript. Part V: Working with Information The last part focuses on how to retrieve, store, modify, and test information to create complex Flash environments that can respond to changing conditions. Appendixes Four appendixes give you quick access to the essential ActionScript objects, actions, key code values, and events. What’s on the CD Accompanying this book is a CD-ROM that contains nearly all the Flash source files for the tasks. You can see how each task was created, study the ActionScript, or use the ActionScript to do further experimentation. You’ll also find a trial version of Flash MX as well as a list of Web links to sites devoted to Flash and showcasing the latest Flash examples, with tutorials, articles, and advice. Additional Resources Use the Web to your advantage. There is a thriving international community of Flash developers; within it you can share your frustrations, seek help, and show off your latest Flash masterpiece. There are free bulletin boards and mailing lists for all levels of Flash users. Begin your search for Flash resources with the list of Web sites on the accompanying CD and with the Answers panel in the Flash application, which provides links to the Flash developer community on the Web. What’s New in Flash MX