Flash ActionScript: Your Visual Blueprintfor Creating Flash -enhanced Web Sites 0764534254, 0764536575

This great guide uses the VISUAL approach to cover features of ActionScript. Take in all the information in two-page spr

285 23 9MB

English Pages 338 Year 2002

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Flash™ ActionScript......Page 1
Front of Book......Page 2
General Info......Page 3
about maranGraphics......Page 5
Credits & Acknowledgments......Page 6
About the Author & Author's Acknowledgements......Page 7
Dedication......Page 8
Table of Contents......Page 9
How to Use This Book......Page 15
FLASH INTERFACE......Page 18
SCENE PANEL......Page 19
CREATE LAYERS......Page 20
CREATE GRAPHICS......Page 22
CREATE A SYMBOL......Page 24
CREATE AN INSTANCE......Page 26
CREATE A BUTTON......Page 28
CREATE ANIMATION......Page 30
ADD SOUND......Page 32
CREATE A MOVIE CLIP......Page 34
CREATE STATIC TEXT BOXES......Page 36
CREATE INPUT TEXT BOXES......Page 38
CREATE DYNAMIC TEXT BOXES......Page 39
USING THE ACTIONS PANEL......Page 40
ASSIGN ACTIONSCRIPT TO A BUTTON......Page 44
ASSIGN ACTIONSCRIPT TO A MOVIE CLIP......Page 45
ASSIGN ACTIONSCRIPT TO A FRAME......Page 46
PUBLISH MOVIES......Page 48
INTRODUCTION TO ACTIONSCRIPT SYNTAX......Page 52
TEST A MOVIE......Page 54
ENTER THE TEST ENVIRONMENT......Page 56
ADD COMMENTS......Page 58
STOP A MOVIE......Page 60
PLAY A MOVIE......Page 62
JUMP TO A FRAME OR SCENE......Page 64
SET MOVIE QUALITY......Page 66
OPEN A WEB PAGE......Page 68
COMMUNICATE WITH THE FLASH PLAYER......Page 70
CREATE OBJECTS USERS CAN DRAG......Page 72
PRINT A MOVIE......Page 76
CHECK FRAME LOAD......Page 78
INTRODUCTION TO MOVIE CLIP PROPERTIES......Page 80
NAME AN INSTANCE......Page 82
RENAME AN INSTANCE......Page 83
ADJUST TRANSPARENCY......Page 84
MAKE MOVIE CLIPS INVISIBLE......Page 86
ROTATE MOVIE CLIPS......Page 88
CHANGE THE WIDTH OF MOVIE CLIPS......Page 90
CHANGE THE HEIGHT OF MOVIE CLIPS......Page 92
SCALE THE WIDTH OF MOVIE CLIPS......Page 94
SCALE THE HEIGHT OF MOVIE CLIPS......Page 96
MOVE MOVIE CLIPS ACROSS THE STAGE......Page 98
MOVE MOVIE CLIPS UP AND DOWN......Page 100
SET MOVIE CLIP QUALITY......Page 102
SCOPE OF VARIABLES......Page 104
CAPTURE USER INPUT......Page 105
ASSIGN A VALUE TO A VARIABLE......Page 106
ASSIGN AN OBJECT OR MOVIE CLIP TO A VARIABLE......Page 108
LOAD VARIABLES......Page 110
EXTRACT A CHARACTER FROM A STRING......Page 112
EXTRACT A SUBSTRING FROM A STRING......Page 114
CONCATENATE STRINGS......Page 116
OBTAIN THE LENGTH OF A STRING......Page 118
SEARCH A STRING......Page 120
CHANGE THE CASE OF A STRING......Page 122
CONVERT TO A BOOLEAN......Page 124
CONVERT TO A NUMBER......Page 125
TYPES OF OPERATORS......Page 126
OPERATOR PRECEDENCE AND ASSOCIATIVITY......Page 127
ADD NUMERIC VALUES......Page 128
SUBTRACT NUMERIC VALUES......Page 130
MULTIPLY NUMERIC VALUES......Page 132
DIVIDE NUMERIC VALUES......Page 134
FIND THE MODULO......Page 136
SET VALUES WITH THE INCREMENT OPERATOR......Page 138
SET VALUES WITH THE DECREMENT OPERATOR......Page 140
USING LESS THAN OR GREATER THAN......Page 142
USING LESS THAN OR EQUAL TO OR GREATER THAN OR EQUAL TO......Page 143
USING EQUALITY AND INEQUALITY OPERATORS......Page 144
USING COMPOUND ASSIGNMENT OPERATORS......Page 146
USING LOGICAL OPERATORS......Page 148
USING IF TO TEST A CONDITION......Page 150
USING IF WITH ELSE......Page 152
USING ELSE IF......Page 154
CREATE A CONDITIONAL LOOP......Page 156
USING FOR LOOPS......Page 158
INTRODUCTION TO OBJECTS......Page 160
USING THE MOVIECLIP OBJECT......Page 162
ATTACH A MOVIE CLIP......Page 164
GET BOUNDS......Page 168
SWAP DEPTHS......Page 170
CHECK MOVIECLIP LOAD......Page 172
DETECT COLLISION......Page 174
GET THE X- AND Y-COORDINATES......Page 176
CREATE AN ARRAY......Page 178
FIND THE LENGTH OF AN ARRAY......Page 182
ADD ELEMENTS TO AN ARRAY......Page 184
REMOVE ELEMENTS FROM AN ARRAY......Page 186
EXTRACT OR REVERSE AN ARRAY......Page 188
CONVERT AN ARRAY TO A STRING......Page 190
CHANGE COLORS......Page 192
WORK WITH COLOR TRANSFORM VALUES......Page 194
USING THE MOUSE OBJECTS AND PROPERTIES......Page 196
USING THE DATE OBJECT......Page 198
GET DATE AND TIME VALUES......Page 200
SET THE DATE......Page 202
SET DATE VALUES......Page 204
SET TIME VALUES......Page 206
USING MATHEMATICAL FUNCTIONS......Page 208
WORK WITH POWERS......Page 209
ROUND NUMBERS......Page 210
GENERATE RANDOM NUMBERS......Page 211
FIND NUMERIC VALUES......Page 212
USING THE KEY OBJECT......Page 214
USING THE SOUND OBJECT......Page 218
SET VOLUME AND PANNING......Page 222
USING THE SELECTION OBJECT......Page 224
GET PROPERTIES......Page 226
USING GET TIMER AND GET VERSION......Page 228
USING EVAL......Page 229
CONVERT A STRING TO A NUMBER......Page 230
EVALUATE FOR MATHEMATICAL ERRORS......Page 232
CREATE A SCROLLABLE TEXT BOX......Page 234
CREATE A CUSTOM FUNCTION......Page 236
VIEW THE HIERARCHY OF MULTIPLE MOVIES......Page 238
ASSIGN TARGET PATHS......Page 240
LOAD AND UNLOAD MOVIES AND MOVIE CLIPS......Page 242
USING TELL TARGET......Page 246
USING THE WITH ACTION......Page 248
DUPLICATE MOVIE CLIPS......Page 250
CREATE SMART CLIPS......Page 252
CREATE A SMART CLIP CUSTOM INTERFACE......Page 256
VALIDATE A STRING......Page 260
VALIDATE A DATE......Page 262
SEARCH A TEXT BOX......Page 264
CONVERT SYMBOLS......Page 268
CREATE ROTATION EFFECTS......Page 270
CREATE A COLORING BOOK......Page 272
EMULATE PANELS......Page 274
MOVE AN OBJECT CLOCKWISE......Page 278
MOVE AN OBJECT BACK AND FORTH......Page 279
MOVE AN OBJECT DIAGONALLY......Page 280
MOVE AN OBJECT IN A WAVE-LIKE MOTION......Page 281
CREATE TRIGONOMETRIC SPECIAL EFFECTS......Page 282
USING THE DEBUGGER......Page 284
USING THE OUTPUT WINDOW......Page 286
USING LIST OBJECTS......Page 288
USING LIST VARIABLES......Page 289
DEBUG YOUR SCRIPT......Page 290
KEYS ON THE NUMERIC KEYPAD......Page 292
OTHER KEYS......Page 293
URL ENCODING CHARACTERS......Page 294
LIST OF KEYWORDS......Page 295
HEXADECIMAL COLOR CODES......Page 296
MOVIE CLIP HANDLERS......Page 299
OPERATORS......Page 300
FUNCTIONS......Page 301
ACTIONS......Page 302
PROPERTIES......Page 303
COLOR OBJECT......Page 304
DATE OBJECT......Page 305
MATH OBJECT......Page 306
MOVIECLIP OBJECT......Page 307
SELECTION OBJECT......Page 308
STRING OBJECT......Page 309
WHAT’S ON THE CD-ROM......Page 310
USING THE E-VERSION OF THE BOOK......Page 312
End-User License Agreement......Page 314
Index......Page 316
Other Visual Titles......Page 336
Order Form......Page 338
Recommend Papers

Flash ActionScript: Your Visual Blueprintfor Creating Flash -enhanced Web Sites
 0764534254, 0764536575

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

Flash ActionScript ™

Your visual blueprint for creating Flash-enhanced Web sites Web development tools on CD-ROM! • Macromedia Flash, FreeHand, and Flash Player trial versions • Plus sample graphics, a searchable e-version of the book, and more

Visit us at www. hungryminds.com

Flash ActionScript 

Your visual blueprint for creating Flash-enhanced Web sites

by Denise Etheridge

TM

From ®

&

Best-Selling Books • Digital Downloads • e-Books • Answer Networks • e-Newsletters • Branded Web Sites • e-Learning

New York, NY • Cleveland, OH • Indianapolis, IN

FlashTM ActionScript: Your visual blueprint for creating Flash-enhanced Web sites Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 Copyright © 2002 Hungry Minds, Inc. Certain designs/text/illustrations Copyright © 1992-2002 maranGraphics, Inc., used with maranGraphics’ permission. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher. maranGraphics, Inc. 5755 Coopers Avenue Mississauga, Ontario, Canada L4Z 1R9 Library of Congress Control Number: 2001099316 ISBN: 0-7645-3657-5 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 1V/SQ/QS/QS/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V. for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland. For U.S. corporate orders, please call maranGraphics at 800-469-6616 or fax 905-890-9434. For general information on Hungry Minds’ products and services, please contact our Customer Care Department within the U.S. at 800-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002. For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign-language translations, please contact our Customer Care Department at 800-434-3422, fax 317-572-4002, or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256. For information on licensing foreign or domestic rights, please contact our SubRights Customer Care Department at 212-884-5000. For information on using Hungry Minds’ products and services in the classroom or for ordering examination copies, please contact our Educational Sales Department at 800-434-2086 or fax 317-572-4005. For press review copies, author interviews, or other publicity information, please contact our Public Relations department at 317-572-3168 or fax 317-572-4168. For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470. Screen shots displayed in this book are based on pre-released software and are subject to change.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES.

Trademark Acknowledgments Hungry Minds, the Hungry Minds logo, Visual, the Visual logo, Read Less - Learn More and related trade dress are registered trademarks or trademarks of Hungry Minds, Inc., in the United States and/or other countries and may not be used without written permission. The maranGraphics logo is a registered trademark or trademark of maranGraphics, Inc. Flash, Director Shockwave Studio, Freehand and Dreamweaver UltraDev Copyright © 1994-2000. Macromedia, Inc. 600 Townsend Street, San Francisco, CA 94103 USA. All Rights Reserved. Contains Macromedia Flash software by Macromedia, Inc. Copyright © 1995-1999 Macromedia, Inc. All rights reserved. Macromedia, Flash, Director Shockwave, Freehand, Dreamweaver and UltraDev are trademarks or registered trademarks of Macromedia, Inc. in the United States and/or other countries. All other trademarks are the property of their respective owners. Hungry Minds, Inc. and maranGraphics, Inc. are not associated with any product or vendor mentioned in this book. FOR PURPOSES OF ILLUSTRATING THE CONCEPTS AND TECHNIQUES DESCRIBED IN THIS BOOK, THE AUTHOR HAS CREATED VARIOUS NAMES, COMPANY NAMES, MAILING, E-MAIL AND INTERNET ADDRESSES, PHONE AND FAX NUMBERS AND SIMILAR INFORMATION, ALL OF WHICH ARE FICTITIOUS. ANY RESEMBLANCE OF THESE FICTITIOUS NAMES, ADDRESSES, PHONE AND FAX NUMBERS AND SIMILAR INFORMATION TO ANY ACTUAL PERSON, COMPANY AND/OR ORGANIZATION IS UNINTENTIONAL AND PURELY COINCIDENTAL.

Permissions maranGraphics Certain text and illustrations by maranGraphics, Inc., used with maranGraphics’ permission.

is a trademark of Hungry Minds, Inc.

U.S. Corporate Sales

U.S. Trade Sales

Contact maranGraphics at (800) 469-6616 or fax (905) 890-9434.

Contact Hungry Minds at (800) 434-3422 or (317) 572-4002.

Flash ActionScript 

Your visual blueprint for creating Flash-enhanced Web sites

maranGraphics is a family-run business located near Toronto, Canada.

At maranGraphics, we believe in producing great computer books — one book at a time. maranGraphics has been producing high-technology products for over 25 years, which enables us to offer the computer book community a unique communication process. Our computer books use an integrated communication process, which is very different from the approach used in other computer books. Each spread is, in essence, a flow chart — the text and screen shots are totally incorporated into the layout of the spread. Introductory text and helpful tips complete the learning experience.

rebuild every screen shot to provide the best clarity possible, making our screen shots the most precise and easiest to read in the industry. We strive for perfection, and believe that the time spent handcrafting each element results in the best computer books money can buy. Thank you for purchasing this book. We hope you enjoy it! Sincerely, Robert Maran President

maranGraphics’ approach encourages the left and right sides of the brain to work together — resulting in faster orientation and greater memory retention.

maranGraphics

Above all, we are very proud of the handcrafted nature of our books. Our carefully-chosen writers are experts in their fields, and spend countless hours researching and organizing the content for each topic. Our artists

www.maran.com

[email protected] www.hungryminds.com/visual

CREDITS Acquisitions, Editorial, and Media Development Project Editor Jade L. Williams Acquisitions Editor Jen Dorsey Product Development Supervisor Lindsay Sandman Development Editors Dana Lesh Kathleen McFadden Technical Editor Kyle D. Bowen Editorial Manager Rev Mengle Media Development Manager Laura Carpenter Van Winkle Permissions Editor Laura Moss Media Development Specialist Megan Decreane

Production Book Design maranGraphics® Production Coordinator Maridee Ennis Layout and Graphics Melanie DesJardins LeAndra Johnson Kristin McMullan Jill Piscitelli Betty Schulte Screen Artists Ronda David-Burroughs Mark Harris Jill A. Proll Cover Illustration David E. Gregory Proofreaders Laura L. Bowman, Susan Moritz, Carl Pierce, Marianne Santy Indexer Sherry Massey Special Help Macromedia, Inc., Malinda McCain

ACKNOWLEDGMENTS Hungry Minds Technology Publishing Group: Bob Ipsen, Vice President & Publisher; Richard Swadley, Vice President & Executive Group Publisher; Mary Bednarek, Vice President & Publisher, Networking; Joseph Wikert, Vice President & Publisher, Web Development Group; Mary C. Corder, Editorial Director, Dummies Technology; Andy Cummings, Editorial Director, Dummies Technology; Barry Pruett, Vice President & Publisher, Visual/Graphic Design Hungry Minds Manufacturing: Ivor Parker, Vice President, Manufacturing Hungry Minds Marketing: John Helmus, Assistant Vice President, Director of Marketing Hungry Minds Production for Branded Press: Debbie Stailey, Production Director Hungry Minds Sales: Michael Violano, Vice President, International Sales and Sub Rights

ABOUT THE AUTHOR Denise Etheridge: Denise Etheridge is the president of BayCon Group Incorporated, a consulting firm specializing in software installation, implementation, and training. The BayCon Group Web site features online software tutorials. You can visit http://www.baycongroup.com/flash/00_flash.htm, for Flash tutorials.

AUTHOR’S ACKNOWLEDGMENTS I would like to say thank you to all of people who provided me with assistance or support during the development of this book. Thank you to Neil Salkind and Jennifer Dorsey for providing me with the opportunity and for encouraging me along the way. Thank you to Jade Williams for her editing and project management. And, thank you to all of the editors and staff at John Wiley who assisted Jade. I would like to give a special thanks to David Gregory for assisting with the artwork and Malinda McCain for helping me with this and many other projects.

I dedicate this book to Frederick, Catherine, Freddie, and Erskine Etheridge.

TABLE OF CONTENTS

HOW TO USE THIS BOOK

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .XIV

1) GETTING FAMILIAR WITH FLASH Introduction to Flash and ActionScript ............................................................................2 Create a Scene ....................................................................................................................3 Create Layers ........................................................................................................................4 Create Graphics ..................................................................................................................6 Create a Symbol ..................................................................................................................8 Create an Instance ............................................................................................................10 Create a Button ..................................................................................................................12 Create Animation ..............................................................................................................14 Add Sound ..........................................................................................................................16 Create a Movie Clip ..........................................................................................................18 Create Static Text Boxes ....................................................................................................20 Create Input Text Boxes ....................................................................................................22 Create Dynamic Text Boxes ..............................................................................................23 Using the Actions Panel ....................................................................................................24 Assign ActionScript to a Button ........................................................................................28 Assign ActionScript to a Movie Clip ................................................................................29 Assign ActionScript to a Frame ........................................................................................30 Publish Movies ..................................................................................................................32

2) PROGRAMMING WITH ACTIONSCRIPT Introduction to ActionScript Syntax ................................................................................36 Test a Movie ........................................................................................................................38 Enter the Test Environment ..............................................................................................40 Add Comments ..................................................................................................................42 Stop a Movie ......................................................................................................................44 Play a Movie ......................................................................................................................46 Jump to a Frame or Scene ................................................................................................48 Set Movie Quality ..............................................................................................................50 Open a Web Page ..............................................................................................................52 Communicate with the Flash Player ................................................................................54 Create Objects Users Can Drag ......................................................................................56 Print a Movie ......................................................................................................................60 Check Frame Load ............................................................................................................62

viii

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

3) SETTING MOVIE CLIP PROPERTIES Introduction to Movie Clip Properties ............................................................................64 Name an Instance ..............................................................................................................66 Adjust Transparency............................................................................................................68 Make Movie Clips Invisible ................................................................................................70 Rotate Movie Clips..............................................................................................................72 Change the Width of Movie Clips ....................................................................................74 Change the Height of Movie Clips....................................................................................76 Scale the Width of Movie Clips ........................................................................................78 Scale the Height of Movie Clips........................................................................................80 Move Movie Clips Across the Stage..................................................................................82 Move Movie Clips Up and Down......................................................................................84 Set Movie Clip Quality ......................................................................................................86

4) WORKING WITH VARIABLES AND STRINGS Introduction to Variables and Data Types ......................................................................88 Assign a Value to a Variable ..............................................................................................90 Assign an Object or Movie Clip to a Variable ................................................................92 Load Variables ....................................................................................................................94 Extract a Character from a String ....................................................................................96 Extract a Substring from a String ......................................................................................98 Concatenate Strings ........................................................................................................100 Obtain the Length of a String ........................................................................................102 Search a String ................................................................................................................104 Change the Case of a String ..........................................................................................106 Convert Strings, Numbers, and Booleans ......................................................................108

5) WORKING WITH OPERATORS Understand Precedence ..................................................................................................110 Add Numeric Values ........................................................................................................112 Subtract Numeric Values ................................................................................................114 Multiply Numeric Values ................................................................................................116 Divide Numeric Values ....................................................................................................118 Find the Modulo ..............................................................................................................120 Set Values with the Increment Operator ......................................................................122 Set Values with the Decrement Operator ....................................................................124 Using Less Than or Greater Than ..................................................................................126

ix

TABLE OF CONTENTS

Using Less Than or Equal to or Greater Than or Equal to ..........................................127 Using Equality and Inequality Operators ......................................................................128 Using Compound Assignment Operators ....................................................................130 Using Logical Operators ..................................................................................................132

6) CHANGING THE SCRIPT FLOW Using if to Test a Condition ............................................................................................134 Using if with else ..............................................................................................................136 Using else if ......................................................................................................................138 Create a Conditional Loop ............................................................................................140 Using for Loops ................................................................................................................142

7) USING THE MOVIE CLIP AND ARRAY Introduction to Objects ..................................................................................................144 Using the MovieClip Object ..........................................................................................146 Attach a Movie Clip ........................................................................................................148 Get Bounds ......................................................................................................................152 Swap Depths ....................................................................................................................154 Check MovieClip Load ....................................................................................................156 Detect Collision ..............................................................................................................158 Get the x- and y-Coordinates ........................................................................................160 Create an Array ................................................................................................................162 Find the Length of an Array ............................................................................................166 Add Elements to an Array ..............................................................................................168 Remove Elements from an Array ....................................................................................170 Extract or Reverse an Array ............................................................................................172 Convert an Array to a String ..........................................................................................174

8) WORKING WITH OBJECTS Change Colors ..................................................................................................................176 Work with Color Transform Values ................................................................................178 Using the Mouse Objects and Properties ....................................................................180 Using the Date Object ....................................................................................................182 Get Date and Time Values ..............................................................................................184 Set the Date ......................................................................................................................186

x

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

Set Date Values ................................................................................................................188 Set Time Values ................................................................................................................190 Using Mathematical Functions ......................................................................................192 Raise a Power or Find A Square Root ............................................................................193 Round Numbers ..............................................................................................................194 Generate Random Numbers ..........................................................................................195 Find Numeric Values ........................................................................................................196 Using the Key Object ......................................................................................................198 Using the Sound Object ..................................................................................................202 Set Volume and Panning ................................................................................................206 Using the Selection Object ............................................................................................208

9) DEMYSTIFYING FUNCTIONS Get Properties ..................................................................................................................210 Using Get Timer and Get Version ..................................................................................212 Using Eval ..........................................................................................................................213 Convert a String to a Number ........................................................................................214 Evaluate for Mathematical Errors ..................................................................................216 Create a Scrollable Text Box ..........................................................................................218 Create a Custom Function ..............................................................................................220

10) WORKING WITH MULTIPLE TIMELINES View the Hierarchy of Multiple Movies ........................................................................222 Assign Target Paths ..........................................................................................................224 Load and Unload Movies and Movie Clips ..................................................................226 Using Tell Target ..............................................................................................................230 Using the with Action ......................................................................................................232 Duplicate Movie Clips ....................................................................................................234

11) CREATING SMART CLIPS Create Smart Clips ..........................................................................................................236 Create a Smart Clip Custom Interface ..........................................................................240

xi

TABLE OF CONTENTS

12) USING CREATIVE TECHNIQUES Validate a String ..............................................................................................................244 Validate a Date ................................................................................................................246 Search a Text Box ............................................................................................................248 Convert Symbols ..............................................................................................................252 Create Rotation Effects ....................................................................................................254 Create a Coloring Book ..................................................................................................256 Emulate Panels ................................................................................................................258 Demystify Trigonometric Functions ..............................................................................262 Create Trigonometric Special Effects ............................................................................266

13) DEBUGGING ACTIONSCRIPT Using the Debugger ........................................................................................................268 Using the Output Window ..............................................................................................270 Using List Objects ............................................................................................................272 Using List Variables ..........................................................................................................273 Debug Your Script ............................................................................................................274

14) FLASH ACTIONSCRIPT QUICK REFERENCE Key Code Values ..............................................................................................................276 URL Encoding Characters ................................................................................................278 List of Keywords ..............................................................................................................279 Actions Appended with Num ........................................................................................280 Hexadecimal Color Codes ..............................................................................................280 Button Handlers ..............................................................................................................283 Movie Clip Handlers ........................................................................................................283 Operators ..........................................................................................................................284 Functions ..........................................................................................................................285 Actions ..............................................................................................................................286 Properties ..........................................................................................................................287

xii

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

Array Object ....................................................................................................................288 Boolean Object ................................................................................................................288 Color Object ....................................................................................................................288 Date Object ......................................................................................................................289 Key Object ........................................................................................................................290 Math Object ....................................................................................................................290 Mouse Object ..................................................................................................................291 MovieClip Object ............................................................................................................291 Number Object ................................................................................................................292 Object Object ..................................................................................................................292 Selection Object ..............................................................................................................292 Sound Object ..................................................................................................................293 String Object ....................................................................................................................293

APPENDIX What’s on the CD-ROM ..................................................................................................294 Using the E-Version of the Book ....................................................................................296 Hungry Minds, Inc. End-User License Agreement ........................................................298

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .300

xiii

HOW TO USE THIS BOOK

Flash ActionScript: Your visual blueprint for creating Flashenhanced Web sites uses straightforward examples to teach you how to create powerful and dynamic Web sites. The coding style and examples found in this book are used for instructional purposes. Once you are comfortable working with Flash ActionScript, you can use the coding styles and methods that suit your needs. To get the most out of this book, you should read each chapter in order, from beginning to end. Each chapter introduces new ideas and builds on the knowledge learned in previous chapters. Once you become familiar with Flash ActionScript, this book can be used as an informative desktop reference.

Who This Book Is For If you are looking for a resource that will help you get started learning ActionScript, Flash ActionScript: Your visual blueprint for creating Flash-enhanced Web sites is the book for you. This book will walk you through the basics that you need to get started and familiarize yourself with the essentials of working with Flash ActionScript. No prior experience with ActionScript is required, but familiarity with Flash is assumed. Experience with programming languages is also an asset, but even if you have no programming experience, you can use this book to learn the essentials you need to work with Flash ActionScript.

What You Need To Use This Book The tasks in this book were developed using Flash 5 for Windows 98, 2000, and NT. To perform the tasks in this book, you need Flash 5 and Flash Player installed on your computer. You should also have a Web browser such Internet Explorer or Netscape.

The Conventions In This Book A number of typographic and layout styles are used throughout Flash ActionScript: Your visual blueprint for creating Flash-enhanced Web sites to distinguish different types of information. Courier Font Indicates the use ActionScript.

xiv

Bold Indicates information that you must type. Italics Indicates a new term being introduced.

An Apply It section usually contains a segment of code that takes the lesson you just learned one step further. Apply It sections offer inside information and pointers that can be used to enhance the functionality of your code.

An Extra section provides additional information about the task you just accomplished. Extra sections often contain interesting tips and useful tricks to make working with Flash ActionScript easier and more efficient.

The Organization Of This Book Flash ActionScript: Your visual blueprint for creating Flashenhanced Web sites contains 14 chapters. The first chapter, Getting Familiar with Flash, provides a review of Flash introduces you to the Actions panel. Chapter 2, Programming with ActionScript, introduces you to ActionScript. You learn to play and stop movies, adjust movie quality, jump to a frame or scene, jump to a URL, check whether a frame is loaded, create draggable objects, communicate with Flash Player, and Print Movies. This chapter illustrates ActionScript by stepping you through examples and explaining the syntax of several actions. Chapter 3, Setting Movie Clip Properties, demonstrates how you can use properties. Properties are the attributes associated with a movie clip. For example, the _visible property determines whether a movie clip is visible or hidden. This chapter explains properties and steps you through sample scripts that use properties. Chapter 4, Working with Variables and Strings, shows you how to use variables and manipulate string. Variables can be viewed as containers that store information. You can assign information to a variable or you can use a variable

Flash ActionScript: Your visual blueprint for creating Flash-enhanced Web sites

to collect information from the user, record what a user has done, change values as a movie plays, or evaluate whether a condition is true or false. A string is any sequence of characters consisting of any combination of letters, numbers, or punctuation marks. The ActionScript String object has several methods that enable you to manipulate strings. This chapter explains variables and strings and steps you through sample scripts that use variables and strings. Chapter 5, Working with Operators, explains operators and steps you through sample scripts that use operators. An operator is a character used to specify how to combine, compare, or modify a value in an expression. For example, the plus (+) operator can be used to add two numbers; the Minus (–) operator can be used to subtract two numbers. Chapter 6, Changing the Script Flow, steps you through actions that enable you to change the flow of script. In ActionScript, each statement is executed in order from top to bottom unless you change the flow of a script. Chapter 7, Using the Movie Clip and Array Objects, introduces the MovieClip object, which is the most important object in ActionScript. Since each movie clip has its own Timeline, each movie clip can be a complete animation. Arrays enable you to group values together and are useful when you need to store and retrieve lists of data. The ActionScript Array object has several methods that enable you to manipulate arrays. Chapter 8, Working with Objects, steps you through ActionScript examples that use objects contains several objects that you can use to manipulate symbols and data. For example, the Math object is used to manipulate numbers. You can use the Math object’s round method to round a number. The Color object is used to manipulate color. You can use the methods of the Color object to change the color of a movie clip. Chapter 9, Demystifying Functions, teaches you how to create you own custom functions. Functions are reuseable blocks of ActionScript. You can pass values to a function or you can use a function to obtain values. For example, you use the getVersion function to get the version of Flash Player. This chapter explains functions and steps you through sample scripts that use functions. Chapter 10, Working with Multiple Timelines, explains how to work with multiple Timelines in a single movie. You can lay out the sequence of a Flash movie on a Timeline. Movie clips are mini Flash movies. They each have their own Timeline and their own properties. You can embed a

movie clip within a Flash movie. In fact, multiple instances of a movie clip symbol can be embedded inside of each other. This chapter steps you through sample scripts that work with multiple Timelines. Chapter 11, Creating Smart Clips, teaches you how to create smart clips. A smart clip is a movie clip with ActionScript that can be reprogrammed without using the Actions panel. This enables you to create ActionScripts that people with no programming ability can modify. Chapter 12, Using Creative Techniques, pulls all basics of ActionScript together by combining actions and demonstrating techniques that you can use when creating a Flash movie. Chapter 13, Debugging ActionScript, is on debugging ActionScript. Flash movies that contain ActionScript can become complex. Flash provides you with several tools that can help you troubleshoot your movie. The final chapter, Flash Action Script Quick Reference, contains useful tables of reference material and a summary of commands.

What Is On The CD-ROM The CD-ROM in the back of this book contains the sample code from each of the two-page lessons, as well as the code from most of the Apply It sections. This saves you from having to type the code and helps you quickly get started creating Flash ActionScript programs. The CD-ROM also contains several shareware and evaluation versions of programs that can help you work with Flash ActionScript. An e-version of this book is also available on the companion disc. Chapter 1 provides a very brief overview of how to create text, input text boxes, dynamic text boxes, buttons, and movie clips. Since this book assumes you know Flash, all of the text, input text boxes, dynamic text boxes, buttons and movie clips used in the sample files have been created for you. The sample files all have an FLA extension. Copy the files to the directory of your choice and click Files ➪ Open on the Flash menu to open them.

xv

400

FLASH ACTIONSCRIPT

INTRODUCTION TO FLASH AND ACTIONSCRIPT

F

lash is a graphics and animation software package that enables Web developers to design and deliver lowbandwidth animations and presentations referred to as movies. With Flash, you can create interactive Web pages with both motion and sound. This book is about FLASH INTERFACE

When you open Flash, the screen shown here appears:

2

ActionScript, the scripting language that enables you to add interactivity to your Flash movie. With ActionScript, you can have your Flash movie respond to mouse clicks and key presses, or you can request information from the user and have your Flash movie respond to the information provided.

GETTING FAMILIAR WITH FLASH

1

CREATE A SCENE

U

sing scenes enables you to separate your movie into sections. For example, you can have a scene that displays the title of the movie, a scene that plays the movie, and a final scene that lists the characters. Each scene has its own Timeline and can include its own animation. SCENE PANEL

To create a scene, click View ➪ Scene from the menu. A new Stage and Timeline appears in which you can create your scene. By default, Flash names scenes by assigning them sequential numbers, for example, Scene 1 and Scene 2. You can use the Scene panel to add, remove, duplicate, rename, and change the order of scenes. To open the Scene panel, click Window ➪ Panels ➪ Scene from the menu.

To view a scene, click View ➪ Goto from the menu and then choose the scene to which you want to go.

3

FLASH ACTIONSCRIPT

CREATE LAYERS

W

hen creating a Flash movie, you place individual images and animations on separate layers to prevent them from connecting, erasing, or segmenting each other. You should also use separate layers for sounds, actions, frame labels, and comments. Layers are transparent sheets on which you create the graphics and animations you use in your movie. You can see through each sheet to the layer beneath until you add color. You work on the active layer. You make a layer active by clicking in the layer, or by moving to the Stage and selecting an object on the layer. Flash places a pencil icon next to the layer name of the active layer. Only one layer can be active at a time. As you create objects, they are stacked according to layer. An object on a lower layer will appear as if it is behind an object

on a higher layer. You can change the order of layers and the name of a layer. You can lock a layer to prevent changes to the layer. Flash uses a padlock icon to indicate a locked layer. You can also hide a layer. Hiding a layer is useful when you want to remove certain objects on the Stage from view to make it easier for you to create graphics. You can delete layers when you no longer need them. To assist you when you are drawing graphics, you can create guide layers. You can also create motion guide layers to assist you when creating motion tweens. You can use mask layers to create spotlight effects. Flash also provides you with an option that allows you to view a layer as an outline. You can specify the outline color. Adding layers does not increase the file size of your published movie.

CREATE LAYERS

Layer

⁄ Click Insert ➪ Layer to create a layer above the active layer.

Layer 3

■ A new layer appears above the active layer.

¤ Double-click and type to change the layer name.

‹ Click in the Show/Hide All

4

Layers column to toggle between showing ( ) and ( ) hiding a layer.

› Click in the Lock/Unlock All Layers column to toggle between locking ( ) and unlocking ( ) layers.

ˇ Click in the Show Layers as Outlines column to toggle between Show Normal ( ) and Show As Outline ( ).

GETTING FAMILIAR WITH FLASH

When you draw on an object using the Line, Oval, Rectangle, Pencil, or Brush tool, the object segments. Each segment is an individual object that you can select, move, and reshape. When you cover object A with object B, object B connects to, segments, and erases object A. Place objects on separate layers to prevent them from connecting, segmenting, and erasing.

Layer 3

1

You can use the Layer Properties dialog box to change layer properties. To open the Layers Properties dialog box, choose Modify ➪ Layer from the menu. Use the Name field to name the layer. Select Show to show the layer. Select Lock to lock the layer. Select the Type of layer. Choose from Normal, Guide, Guided, Mask, and Masked. Use the Outline Color option to select the color of the outline. To view a layer as an outline, select View Layer As Outlines. Select a Layer Height. Choose from 100 percent, 200 percent, or 300 percent.

Layer 3

Á Click the layer and drag to

° Click

change the order of a layer.

layer.

‡ Click

· Click

to insert a layer.

to add a guide

‚ Click the Show/Hide,

to delete a layer.

Lock/Unlock, or Outlines icon to affect every layer in the column.

■ Items on lower layers

appear to be behind items on higher layers.

■ The pencil icon indicates this is the active layer.

5

FLASH ACTIONSCRIPT

CREATE GRAPHICS

F

selected objects. Grouping enables you to manipulate several objects as a single object. You use the Arrow tool to select a button or movie clip when you want to associate ActionScript with a button or movie clip.

The Pen tool gives you the ability to draw straight lines and smooth curves. You use the Subselect tool to adjust those lines. Stroke lines outline a graphic. You use the Ink Bottle tool to change the stroke line color, width, or style. Fill colors fill the interior of a graphic. You use the Dropper tool to copy fill and stroke attributes from one object to another. The Eraser tool gives you the ability to erase.

Flash tools have modifiers you can use to set tool options. Color boxes enable you to set the stroke and fill colors associated with each tool. You can swap the stroke and fill colors, set the color to no color, or set the colors to the default colors. The Arrow tool provides you with options for smoothing, straightening, rotating, and scaling objects. The Rectangle tool provides an option for rounding corners. You can set the size and shape of the Brush. The Eraser offers several modes and a faucet that enables you to erase the selected area. When using the Pencil, you can choose to have straight lines, smooth lines, or free-form lines.

lash provides you with several tools you can use to create or modify graphics. You use the Line tool to create straight lines, the Oval tool to create circles and ellipses, and the Rectangle tool to create squares and rectangles. You use the Paint Bucket and Brush tools to add color to images.

You can use the Arrow and Lasso tools to select objects on the Flash Stage. You can group, move, copy, or delete

CREATE GRAPHICS

⁄ Click to select a tool.

¤ Click to select modifiers.

‹ Move to the Stage and drag to create a shape. ■ You can create rectangles

6

with the Rectangle tool ( ), ellipses with the Oval tool ( ), straight lines with the Line tool ( ), paint with the Brush tool ( ), or free-form lines with the Pencil tool ( ), or you can erase with the Eraser tool ( ).

■ You can create a square

with or a circle with by holding down the Shift key as you drag.

GETTING FAMILIAR WITH FLASH

To hide the Toolbox, click Window ➪ Tools from the menu. To bring the Toolbox back, click Window ➪ Tools again. Use the Hand tool to move the Stage. Use the Zoom tool to zoom in on the Stage. You can also click View ➪ Zoom In to zoom in on the Stage, or View ➪ Zoom Out to zoom out. To change the magnification, click View ➪ Magnification and select a magnification level.

■ If you selected the Ink Bottle ( ), Paint Bucket ( ), or Dropper tool ( ), move to the Stage and click the mouse.

■ You can click the stroke

line to change the stroke color with , the fill color to change the fill with , or set a stroke or fill color with .

1

You can click Windows ➪ Panels ➪ Fill to open the Fill panel. The Fill panel enables you to select color, gradients, or bitmap fills. You can create your own gradients. You can click any bitmap in the Library as a bitmap fill. You can click Windows ➪ Panels ➪ Stroke to select a stroke color, style, or line weight. Clicking Windows ➪ Panels ➪ Mixer enables you to create colors.

› Click to select the Lasso or

ˇ Move to the Stage and

Arrow tool.

drag the mouse to select an object.

■ The pointer changes to the icon that represents the tool you selected.

■ Use

to place a rectangle around the selected area.

■ Use

to draw the area you want to select.

7

FLASH ACTIONSCRIPT

CREATE A SYMBOL

C

reating and using symbols enables you to share graphics, movie clips, buttons, and sounds among movies. A symbol is a reusable graphic, button, movie clip, or sound. Every Flash movie has a Library, which stores symbols. When you create a symbol, it automatically becomes part of the Library. Graphics are static images. You can place graphics on the Timeline of a movie, but you cannot attach ActionScript to a graphic. Buttons are interactive graphics that can respond to user actions. You use ActionScript to give Flash instructions on how to respond when the user clicks, rolls the pointer over, or performs some other action in relation to a button. Buttons have their own Timeline. Movie clips are reusable animations that have their own Timeline. You can place a movie clip on a button Timeline

to create an animated button. You use ActionScript to give Flash instructions on how to respond when the user clicks, rolls the pointer over, or performs some other action in relation to a movie clip. Symbols speed up the playback of your movies, because the browser only needs to download them once. Using symbols enables you to share graphics, movie clips, buttons, and sounds among movies. You can set up permanent libraries and link to items in the permanent libraries from any Flash movie. You can open any Flash movie as a shared library to make the library items from that movie available to the current movie. Flash ships with several libraries containing buttons, graphics, and movie clips that you can use in your own movies. You can create a symbol, import a symbol, or convert an object on the Stage into a symbol. You create symbols in the symbol-editing mode.

CREATE A SYMBOL

New Symbol...

Ctrl+F8

■ Make sure nothing on the Stage is selected.

⁄ Click Insert ➪ New Symbol to open the Symbol Properties dialog box.

■ The Symbol Properties dialog box appears.

¤ Type a symbol name. ‹ Click to select a behavior.

8

› Click OK. ■ Flash changes to the symbol-editing mode.

GETTING FAMILIAR WITH FLASH

You can convert any selection on the Stage into a symbol. To reduce the file size of your movies, consider turning background images into symbols so you can reuse them. To convert an object on the Stage into a symbol, use the Arrow tool to select the object. Click Insert ➪ Convert to Symbol to open the Symbol Properties dialog box. Click to select Movie Clip, Graphic, or Button as the behavior. Click OK.

1

When you create a symbol from a selection on the Stage, the selection becomes an instance of the symbol. You will no longer be able to edit the object directly. To edit the symbol, you must move to the symbol-editing mode. To move to the symbol-editing mode, use the Arrow tool to select the symbol and click Edit ➪ Edit Symbols. When you have completed editing your symbol, click Edit ➪ Edit Movie to exit the symbol-editing mode. When you modify a symbol, Flash updates every instance of the symbol in the movie. When editing a symbol, you can use all of the drawing tools and you can import content.

Circle

ˇ Click to select a drawing

‡ Click the Scene button to

■ The main Timeline returns.

· Click the symbol name to

tool and create the symbol content.

exit symbol-editing mode.

° Click the Show Library

see the symbol in the Item Preview window.

Á Create a symbol.

icon (

) to open the Library.

■ The symbol you created appears in the preview window.

9

FLASH ACTIONSCRIPT

CREATE AN INSTANCE

C

reating and using instances of a symbol can dramatically reduce the size of your Flash movie. An instance is a copy of a symbol. Each symbol can have an unlimited number of copies — or instances. You can change the color, tint, size, shape, rotation, function, and other properties of an instance. Changes you make to an instance do not change the symbol itself or other instances of the symbol. Brightness refers to the relative lightness or darkness of an image. Black has a brightness of -100 percent. White has a brightness of +100 percent. Tint refers to the color or hue of an instance, for example, red, blue, or green. Alpha refers to the transparency of an instance. An instance with an alpha property of 0 percent is completely transparent. An instance with an alpha property of 100 percent is

completely opaque. You use the Effect panel to change the brightness, tint, or alpha property of an instance. An instance can have a behavior type of graphic, button, or movie clip. Instances inherit their behavior type from the symbol. To change an instance behavior type, use the arrow tool to select the instance, then open the Instance panel. In the Instance panel Behavior field, select from Graphic, Button, or Movie Clip. Using instances of a symbol dramatically reduces the file size of your movie, because saving instances of an image requires less space than saving a complete description of an image each time you use it. You create an instance by opening the Library and dragging the instance from the Library onto the Stage.

CREATE AN INSTANCE

Library

⁄ Click to select a keyframe.

¤ Click Window ➪ Library to open the Library.

10

Ctrl+L

GETTING FAMILIAR WITH FLASH

You use the Effect panel to change the brightness, tint, or alpha property of an instance. To open the Effect panel, click Window ➪ Panels ➪ Effect. Select Brightness and use the brightness slider to set the brightness to a value between -100 and 100. Select tint to change color using a color box or by setting Red, Green, and Blue values. Select Alpha and use the Alpha slider to set the brightness to a value between 0 and 100 percent. Select Advanced to adjust both the color and alpha values.

You can use the Instance panel to change the behavior type of an instance. To open the Instance panel, click Window ➪ Panels ➪ Instance or click Modify ➪ Instance on the menu. Use the Arrow Tool to select the instance for which you want to change the behavior. Use the Behavior field to change the behavior of your instance.

Circle

■ The Library window appears.

‹ Click the symbol name.

1

Circle

› Drag the symbol from the Library onto the Stage.

■ An instance of the symbol appears on the Stage.

11

FLASH ACTIONSCRIPT

CREATE A BUTTON

B

uttons enable you to add interactivity to your Flash movie. The user clicks a button to cause an action to occur. For example, the user can click a button to open a Web page. Buttons have four states: Up, Over, Down, and Hit. The Up state is how the button appears to the user when the pointer is not over the button. The Over state is how the button appears to the user when the pointer is over the button. The Down state is how the button appears to the user when the user clicks the mouse while the pointer is over the button. The Hit state defines the area that responds to user actions. Make sure that your Hit state is at least large enough to encompass the graphics used in the other three states. You can make the Hit states larger than the other states. The Hit state is not visible to the user.

When you create a button, Flash presents you with a fourframe timeline, with one frame representing each of the four button states. To define the appearance of a button state, you can create or import a graphic for each of the four states. You can use any graphic or movie clip when defining the appearance of a button state. You use movie clips to create animated buttons. You cannot use another button to define a button state. You can enable a button to test it. You use ActionScript to define the action that will occur when the user clicks the button. You can use buttons to analyze user input, respond to user input, load or unload a movie, or perform a myriad of other tasks.

CREATE A BUTTON

New Symbol...

Ctrl+F8

⁄ Click Insert ➪ New Symbol to open the Symbol Properties dialog box.

■ The Symbol Properties dialog box appears.

¤ Type a symbol name. ‹ Click to select Button as the behavior („ changes to ´).

12

› Click OK. ■ Flash moves to the

symbol-editing mode.

GETTING FAMILIAR WITH FLASH

Enabling a button lets you test the button. Flash disables buttons by default, making it easier for you to work with them while you create your movie. To enable a button for testing, click Control ➪ Enable Simple Buttons. A check mark appears next to the selection on the menu. When you move your pointer over the button, the Over state appears. When you click while the pointer is over the button, the Down state appears. To select an enabled button, use the Arrow tool to draw a rectangle around the button. To move an enabled button, select it with the Arrow tool and use the arrow keys to move the button around the Stage. To disable a button after enabling it, click Control ➪ Enable Simple Button again. When you are creating a movie, it is best to leave your buttons disabled and only enable your buttons for testing.

Keyframe

1

You can import the image you use to define a button state. To import an image click File ➪ Import, locate the image you want to import, and click Open.

F8

ˇ Define the appearance of the Up state by drawing or placing an instance on the Stage.

Á Click Insert ➪ Keyframe.

■ Flash inserts a keyframe and copies the Up state image to the Over state frame. You can change the image if you want.

■ The main Timeline returns.

· Drag an instance of the

° Click the Show Library

button from the Library onto the Stage.

icon (

) to open the Library.

■ An instance of the button appears on the Stage.

■ Repeat steps 5 and 6 for the Down and Hit states.

‡ Click the Scene button to exit the symbol-editing mode.

13

FLASH ACTIONSCRIPT

CREATE ANIMATION

Y

ou use Flash to create animation. You can rotate or move objects, fade them in and out, or change their size or shape. You can animate objects independently or have them move and change in concert. You create animation by changing the content of successive frames. Flash utilizes two types of animation: frame-byframe and tweened. In frame-by-frame animation, you place an image in each successive frame of the animation. In tweened animation, you place an image in a start frame and in an end frame. Flash then creates the images in the frames in between by varying size, location, or other attributes. Tweened animation utilizes significantly less file space than frame-by-frame animation, because Flash stores only the values for changes in the animation. With frameby-frame animation, Flash stores the values for each frame.

The two types of tweened animation are motion and shape. With motion tweening, you set the position, rotation, skew, color, or size of an object in a start frame; then you change the position, rotation, skew, color, or size of an object in an end frame. Flash interpolates the frames in between. With shape tweening, you draw a shape in a start frame and then draw another shape in an end frame. Flash again interpolates the frames in between, causing the shape in the start frame to turn into the shape in the end frame. The start and end frames of a tween must be keyframes. If you change the number of frames between the start and end frames, Flash automatically tweens the frames again. You can tween instances and text.

CREATE ANIMATION

Create Motion Tween

⁄ Click to select a keyframe.

¤ Draw an object on the

› Click Insert ➪ Create

ˇ Click in the frame in

Stage or drag an instance from the Library.

Motion Tween.

which you want the animation to end.

‹ Click to select the Keyframe in which you placed the object.

14

■ If you draw an object on

the Stage, Flash automatically converts the object to a symbol and names the object Tween1.

GETTING FAMILIAR WITH FLASH

1

You can use the Frame panel to adjust a tween. To open the Frame panel click Modify ➪ Frame from the menu. FIELD

Frame

FUNCTION

Label

Give a label name to a frame.

Tweening

Select a tween type of None, Motion, or Shape.

Scale

Select if tweening the size of the object.

Easing

Type -1 to -100 to start the tween slowly and accelerate at the end. Type 0 to 100 to start the tween rapidly and decelerate at the end.

Rotate

Select CW to rotate the object clockwise. Select CCW to rotate the object counter clockwise. Select Auto to rotate object once in the direction requiring the least motion.

F5

Á Click Insert ➪ Frame.

■ A broken line appears on

the Timeline. The line indicates that you have begun a tween.

■ An arrow line appears. An

arrow line indicates that your tween is complete.

‡ Move, adjust the size, change the properties, or rotate the object you want to tween.

15

FLASH ACTIONSCRIPT

ADD SOUND

Y

ou can add spice to your Flash movie by adding sound. Flash lets you loop, edit, and compress your sound files and create sound effects.

You can import sounds. Imported sounds are stored in the Library. Sounds can be either event sounds or stream sounds. Event sounds are continuous play; they continue to play regardless of what happens in the movie. Event sounds must download completely before they begin. You synchronize Stream sounds with an event. Stream sounds can begin playing before they download completely. Flash provides compression options that enable you to control the quality and size of sounds in your movie. You set the compression options for individual sounds by double-clicking the Sound icon in the Library to open the Sound Properties dialog box. You define the settings for all sounds in the Publish Settings dialog box.

In the Sound panel, you can choose a sound effect, a synchronization type, and the number of times a sound should loop. There are four synchronization types: Event, Start, Stop, and Stream. When the playhead enters an Event sound’s frame, the sound begins and then plays in its entirety. If an Event sound has not completed playing when the movie stops, the sound continues to play. The Start synchronization is the same as the Event synchronization, except if the sound is already playing when the playhead enters the frame, a new instance of the sound begins. The Stop option stops the playing of a sound. Flash synchronizes a Stream sound with an event; a Stream sound cannot play longer than the number of frames it occupies. A Stream sound stops when the movie stops.

ADD SOUND

Import...

Ctrl+R

horn.wav

⁄ Click File ➪ Import. ■ The Import dialog box appears.

¤ Click to select your sound file.

16

■ You may need to click

to locate your sound file if it does not appear in the Import window.

‹ Click Open to open the file.

■ Flash sends the sound file

Á Click Play (

to the Library.

sound.

› Click

‡ Drag the sound onto the

to open the

) to hear the

Library.

Stage.

ˇ Click the sound name to

■ The sound appears on the

select the sound.

Timeline.

GETTING FAMILIAR WITH FLASH

1

The Effect field of the sound panel provides the following sound effect options: EFFECT

DESCRIPTION

None

No sound effect.

Left Channel

The sound plays in the left channel only.

Right Channel

The sound plays in the right channel only.

Fade Left to Right

The sound gradually shifts from the left channel to the right channel.

Fade Right to Left

The sound gradually shifts from the right channel to the left channel.

Fade In

The volume of the sound gradually increases.

Fade Out

The volume of the sound gradually decreases.

Custom

Lets you create channel and fade effects.

Panels

Sound

° Click Window ➪ Panels ➪ Sound to open the Sound panel.

■ The Sound panel appears. · Click effect.

to select an

‚ Click

to select a synchronization option.

— Type the number of times the sound should loop.

■ The sound is now part of your movie.

17

FLASH ACTIONSCRIPT

CREATE A MOVIE CLIP

M

ovie clips enable you to reduce the size of your movie by utilizing multiple instances of the same clip. Movie clips are mini Flash movies with their own Timeline and their own properties. You can turn any Flash animation into a movie clip symbol and then use multiple instances of the movie clip. To distinguish between the multiple instances, you give each instance a name. You can embed a movie clip symbol within a Flash movie. Moreover, you can embed multiple instances of a movie clip symbol within each other. You can place a movie clip on the Timeline of the main movie or on the Timeline of another movie clip. Creating a movie clip is easy. First, you create your animation. Then you copy your animation and turn it into a symbol.

To keep your file size down, use movie clips for repetitive actions such as the spinning of a propeller on an airplane. You can use ActionScript to manipulate movie clips to create complex nonlinear interactive movies. See Chapter 7 for more information on working with the Movie Clip object. You can change the position, appearance, and other properties of a movie clip. See Chapter 3 for more information on movie clip properties. Using a movie clip to define the appearance of a button state enables you to create animated buttons. You can also change your movie clip into a smart clip. A smart clip is a movie clip with ActionScript that designers can reprogram without using ActionScript themselves. With smart clips, designers who do not know ActionScript can easily utilize its power.

CREATE A MOVIE CLIP

New Symbol...

Copy Frames

Ctrl+Alt+C

⁄ Create an animation. Note: See page 14 for information on creating an animation.

¤ On the Timeline, select every frame you want to include in the movie clip.

18

Ctrl+F8

‹ Click Edit ➪ Copy Frames to copy the frames you selected.

ˇ Click Insert ➪ New

‡ Click to select Movie Clip

Symbol to open the Symbol Properties dialog box.

as the behavior („ changes to ´).

› Deselect your selection by

Á Type a symbol name.

° Click OK.

clicking anywhere on the Stage.

■ Flash changes to the symbol-editing mode.

GETTING FAMILIAR WITH FLASH

Creating an animated button is easy. Start by creating your animation. Convert your animation to a movie clip. Create a button. Use the animation to define the Up, Over, Down, or Hit state. To select everything on every layer, click Edit ➪ Select All on the menu. To deselect everything on every layer, click Edit ➪ Deselect All. To select a layer, click the layer name. To select a frame, click in the frame. To select a block of frames, click in the start frame, hold down the shift key, and then click in the end frame. To add to a selection, hold down the shift key as you make your selection.

Paste Frames

1

To distinguish between instances of a movie clip, you must give each instance a name. To reference a movie clip in ActionScript, in most cases the movie clip must have a name. To name a movie clip instance, use the Arrow tool to select the instance, click Window ➪ Panels ➪ Instance to open the Instance panel, and then type a name in the Name field.

Ctrl+Alt+V

· Click in Frame 1 of Layer 1 on the Timeline.

‚ Click Edit ➪ Paste Frames.

■ Flash pastes the frames

you copied into the Timeline of the movie clip symbol.

— Click the Scene button to exit the symbol-editing mode.

■ Your movie clip appears in the Library.

19

FLASH ACTIONSCRIPT

CREATE STATIC TEXT BOXES

T

ext boxes enable you to include text in your movie, accept user input, and display dynamic text. You use static text boxes to display text that will not change, dynamic text boxes to display text that will change, and input text boxes to request information from the user. Your text box can be single line, fixed width, or editable. Single line text boxes expand as you type. A round handle in the upper-right corner of a text box indicates that the box is a single line text box. Fixed width text boxes wrap words as you type. A square handle in the upper right corner of a text box indicates that the text box is a fixed width text box. Editable text boxes let you accept user input or dynamically display text. A square or round handle in the bottom right corner of the text box indicates that the text box is an editable text box.

Flash gives you the ability to set the font, size, style, and alignment of your text, using the Text menu options. You can set the color of the font by using the color modifier. You can use embedded or device fonts. When you use a font that you have installed on your system, Flash embeds the font in the movie. Flash does this to ensure that the font will display properly as the movie plays. As an alternative to an embedded font, you can use a device font. When using device fonts, Flash uses the font on the local computer that most closely matches the device font you chose. Because Flash does not embed device fonts, they reduce your file size. Also, if the point size of your font is less than 10, using a device font can yield a crisper, sharper text. Flash supplies you with three device fonts: _sans, _serif, and _typewriter.

CREATE STATIC TEXT BOXES

Options...

⁄ Click Text ➪ Options to open the Text Options panel.

20

■ The Text Options panel appears.

¤ Click

to select Static Text from the drop-down list.

GETTING FAMILIAR WITH FLASH

You can make your text selectable. Making text selectable enables the user to click and drag to highlight text in your movie. You antialias your text to smooth the edges. To antialias, click View ➪ Antialias on the menu. Antialiasing works best with larger fonts. If you have large amounts of text, antialiasing can slow down the playback of your movie.

1

You can set the alignment, margins, indents, and spacing of your text boxes. You use alignment to align your text with the left edge, right edge, or center of the text box. You can also use the alignment to justify your text. Use the margin settings to specify the amount of space from the edge of the text box and where the text begins or ends. Use indent to specify where the first line of text for each paragraph will begin. Use spacing to set the amount of space between each line of text. To set the alignment, margins, indents, and spacing, click Text ➪ Paragraph from the menu.

Options...

‹ Click the Text tool (

) to

select it.

› Click in the color box ( ) to select the color of your font.

ˇ Click the Stage for a single line text box or click the Stage and drag for a fixed width text box.

Note: See page 23 for information on creating a dynamic text box, and page 22 for information on creating an input text box.

Á Type your text.

‡ Click Text ➪ Option to set your text options.

° Click Use Device Fonts to

■ The Text Options panel

· Click Selectable to make text selectable.

appears.

use device fonts.

■ The text appears on the Stage.

21

FLASH ACTIONSCRIPT

CREATE INPUT TEXT BOXES

Y

ou use input text boxes to request information from the user. You will frequently use input text boxes when creating forms. Using the Text options panel, you associate each input text box with a variable. Variables store information. To learn more about variables, see Chapter 4. Flash assigns the information the user types in an input text box to the variable you specify. You can use ActionScript to read the user input and respond to the user. When creating an input text box, you can set several options in the Text options panel. In the drop-down list, select from Single Line, Multiline, or Password. Select Single Line to display user input on a single line. If the text is too long to fit in the text box, the text box will scroll. Select Multiline and check the Word Wrap box to display the user

input on multiple lines and have the input wrap at the end of the box. If you do not select Word Wrap, Flash will move to a new line when the user presses Enter. Select Password to have asterisks display as the user types. This option enables you to create a form with password protection. Select HTML to save the formatting with the HTML tags. Select Border/Bg to display a background behind and a border around the text. Type the name you want to give the variable in the Variable field. Type the maximum number of characters the user can enter in the Max. Chars. field. Click one or more Embed Fonts buttons to specify which font characters Flash should embed.

CREATE INPUT TEXT BOXES

Options...

⁄ Click the Text tool ( ¤ Click font color.

to select a

).

‹ Click Text ➪ Options to open the Text Options panel.

■ The Text Options panel

‡ Click to select HTML, Border/Bg, or Word Wrap.

› Click

° Click the Stage for a single line text box or click the Stage and drag for a fixed width text box.

appears.

to select Input Text from the drop-down list.

ˇ Click

to select from Single Line, Multiline, or Password.

22

Á Type a variable name.

■ The text box appears on the Stage.

GETTING FAMILIAR WITH FLASH

1

CREATE DYNAMIC TEXT BOXES

Y

ou can use dynamic text boxes to display text that updates or to display text in response to user input. Using the Text Options panel, you associate each dynamic text box with a variable. Variables store information. Flash assigns the information in the box to the variable you specify. To learn more about variables, see Chapter 4. When creating a Dynamic text box, you can set several options by using the Text Options panel. In the drop-down list, you select from Single Line or Multiline. You can select Single Line to display output on a single line. You can select Multiline and check the Word Wrap box to display the text on multiple lines and have the text wrap at the end of the box.

Select HTML to save the formatting with the HTML tags. Select Border/Bg to display a background behind and a border around the text. Type the name you want to give the variable in the Variable field. Click to select Selectable to allow the user to select the text. Click one or more Embed fonts buttons to specify which font characters Flash should embed.

If you select HTML when you select Dynamic Text or Input Text in the Text Option panel, Flash with create or save simple HTML formatting tags. This allows you to save the font name, style, color, and size associated with the text. The following HTML tags are supported by Flash: , , , , , ,

, .

CREATE DYNAMIC TEXT BOXES

Options...

⁄ Click ¤ Click font color.

. to select a

‹ Click Text ➪ Options to open the Text Options panel.

■ The Text Options panel

‡ Click to select HTML,

appears.

Border/Bg, or Selectable.

› Click to select Dynamic Text from the drop-down list.

° Click the Stage for a

ˇ Click to select Single Line or Multiline. Á Type a variable name.

single line text box or click the Stage and drag for a fixed width text box.

■ The text box appears on the Stage.

23

FLASH ACTIONSCRIPT

USING THE ACTIONS PANEL

A

ctionScript is the scripting language that enables you to add interactivity to your Flash movie and to control Flash objects. You can use ActionScript statements to instruct Flash on how to respond to the user mouse clicks and key presses, or you can use ActionScript to have your movie respond to information provided by the user. You can create ActionScript in the Action panel. ActionScript is always associated with a frame, button, or movie clip. Using the Arrow tool, you select the frame, button, or movie clip with which you want to associate ActionScript; then you open the Action panel. The Action panel has two modes: Normal and Expert. In Normal Mode, fields in a Parameters panel prompt you for the correct statement arguments. In Expert Mode, you write and edit your statements in a text box. Working in Expert Mode is similar to using a text editor.

In Normal Mode, you can select statements from the Toolbox list on the right side of the Action panel. The Toolbox list divides statements into the following categories: Basic Actions, Actions, Operators, Functions, Properties, and Objects. You can double-click statements to select them. You can also select statements by clicking the Add a Statement button, which categorizes statements the same way the Toolbox list does. You use the Delete a Statement button to delete statements. The Parameters panel prompts you for the arguments related to the statements you select. After you select a statement, the statement appears in the Actions list on the right side of the Action panel. You can change the order of statements by clicking the Change the Statement Order buttons. The up arrow moves the statements up. The down arrow moves the statements down. You can also move a statement by clicking it and dragging.

USING THE ACTIONS PANEL

Basic Actions

Go To

Esc+go

gotoAndPlay (1);

⁄ In the Toolbox list, click

¤ Double-click a statement

‹ Click the Add a Statement

› Click a statement from the

the category name to display the statements in the category.

to select it.

button ( ) to display statement categories.

drop-down menu.

24

GETTING FAMILIAR WITH FLASH

1

You can write ActionScript by using a text editor and using the #include action to call the text file that contains your ActionScript. The syntax for the #include action is #include "filename.as"

You can name your file anything you want. Use AS for the file extension. The filename.as argument represents the relative path to the file. If the movie file and the ActionScript text file are in the same folder, the path is filename.as. If the ActionScript text file is in a subfolder, the path to the file is foldername/filename.as. When you test, publish, or export your movie, the text file must be present. ActionScript replaces the #include statement with the contents of the file.

gotoAndPlay (1);

ˇ Click the Delete a Statement button ( ) to delete a statement.

gotoAndPlay (1);

Á Click

to open the Parameters panel.

° Click this Change the

■ The Parameters panel

appears at the bottom of the panel.

Statement Order button ( ) to move a statement down.

■ The Action list displays the script.

‡ Click this Change the Statement Order button ( to move a statement up.

)

CONTINUED

25

FLASH ACTIONSCRIPT

USING THE ACTIONS PANEL (CONTINUED)

Y

ou can change the size of the Toolbox list by dragging the vertical splitter bar that appears between the Toolbox list and the Actions list. You can expand or collapse the Toolbox list by clicking the left or right arrow button that appears on the splitter bar. In Expert Mode, you type your statements in the Actions list just as you would if you were using a text editor. You can also add statements by selecting them from the Toolbox list or by using the Add a Statement button. In Expert Mode, there is no Parameters panel to prompt you for arguments, the Change the Statement Order buttons are inactive, and the Delete a Statement button is not available. In addition, Expert Mode does not have a Basic Actions category.

You can switch between Normal and Expert Mode. Changing modes might change the format of your script, so it is best to stick to a single mode per script. You cannot convert Expert Mode scripts with errors to Normal Mode. You can convert Normal Mode scripts with errors to Expert Mode, but you must correct the errors before exporting the script. When you switch from Normal Mode to Expert Mode, Flash preserves the indentation and formatting. When you switch from Expert Mode to Normal Mode, Flash strips any white space you have added and any indentations you have made.

USING THE ACTIONS PANEL (CONTINUED)

gotoAndPlay (1);

· Drag the splitter bar to

‚ Click

change the size of the Toolbox list.

Action list.

26

to collapse the

GETTING FAMILIAR WITH FLASH

1

In addition to Normal Mode and Expert Mode, the Options menu in the Action panel offers several other features. Use GoTo Line to move to a specified line in your script. Use Find to find a string of characters. Use Find Again to continue your search. Use Replace to find and replace a string of characters. Use Print to print your script. Choose Font Size from the Options menu to select a small, medium, or large font. Click Check Syntax to have Flash check your script for syntax errors. Select Colored Syntax to have the various elements of your statements appear in different colors. This helps you debug your code. When you turn on Colored Syntax, keywords and predefined identifiers appear in blue, properties appear in green, comments appear in magenta, and quoted strings appear in gray. A check mark next to Colored Syntax means it is on; no check mark means it is off. Use Show Deprecated Syntax to have all deprecated syntax display in the Toolbox list with green highlighting. This feature works only if you have the Export Version in the Publish Settings dialog box set to Flash 5. If you set the Export Version to Flash 4 or lower, ActionScript highlights in yellow any syntax not available in the version you selected.

gotoAndPlay (1);

— Click Action list.

to expand the

gotoAndPlay (1);

± Click

to change modes or select options.

■ Use the Actions panel to add ActionScript.

27

FLASH ACTIONSCRIPT

ASSIGN ACTIONSCRIPT TO A BUTTON

A

ssigning actions to buttons enables you to create objects users can drag and objects that respond to user input or perform myriad other tasks in response to mouse clicks or pointer movements. You should assign actions to the instance of the button — not to the Up, Over, Down, or Hit frames on the button Timeline. If you assign an action to a button instance, other instances of the symbol are not affected. When assigning actions to buttons, you must use a handler to determine the mouse event that will trigger the action. All button handlers begin with the word on and end with the event to which the handler responds enclosed in parentheses. In Normal Mode, Flash assigns the on(release) handler by default. The on(release) handler performs specified actions when the pointer is over the button and the user releases the mouse. The on(press) handler performs specified actions when the pointer is over the button and the user

presses the mouse. Use the on(releaseOutside) handler to perform specified actions when the user drags the pointer outside the button area and then releases the mouse. You can use the on(rollOver) handler to perform specified actions when the user rolls the pointer over the button. You can use the on(rollOut) handler to perform specified actions when the user rolls the pointer over and then outside of the button area. Use the on(dragOver) handler to perform specified actions when the user clicks the button, drags the pointer away from the button, and then drags the pointer back over the button. Use the on(dragOut) handler to perform specified actions when the pointer is over the button and the user presses the mouse and then drags the pointer outside the button area. The on(keyPress, "key") handler performs specified actions when the user presses a specified key.

ASSIGN ACTIONSCRIPT TO A BUTTON

on (release) {

Actions

⁄ Use the Arrow tool ( select a button.

) to

Ctrl+Alt+A

¤ Click Window ➪ Actions to open the Object Actions panel.

■ The Object Actions panel appears.

‹ Click Basic Actions. › Double-click On Mouse Event to select a handler.

■ ActionScripts defaults to on(release).

ˇ Click a check box to select a handler. ■ Use handlers to specify

when Flash should execute ActionScript.

28

GETTING FAMILIAR WITH FLASH

1

ASSIGN ACTIONSCRIPT TO A MOVIE CLIP

A

ssigning ActionScript to a movie clip enables you to have your movie perform a variety of tasks when the user clicks or rolls the pointer over the movie clip. If you assign an action to a movie clip instance, other instances of the symbol are not affected. When assigning actions to movie clips, you must use a handler to determine the mouse event that will trigger the action. All movie clip handlers begin with the word onClipEvent and end with the event to which the handler responds enclosed in parentheses. In Normal Mode, Flash assigns the onClipEvent(load) handler by default if you select OnClipEvent from the Action list or if you select an action without specifying a handler. The onClipEvent(load) handler executes specified actions the first time the movie clip appears on the Timeline. The onClipEvent(unload) handler executes specified actions in the first frame after you remove the movie clip from the Timeline.

Use the onClipEvent(enterFrame) handler to perform specified actions each time the playhead enters the frame. Use the onClipEvent(mouseMove) handler to perform specified actions every time the user moves the mouse. Use the onClipEvent(mouseDown) handler to perform specified actions when the user presses the mouse. Use the onClipEvent(mouseUp) handler to perform the specified actions when the user releases the mouse. The onClipEvent(keyDown) handler performs the specified actions when the user presses any key. The onClipEvent(keyUp) handler performs the specified actions when the user releases any key. The onClipEvent(data) handler performs the specified actions when ActionScript receives data. You assign ActionScript to a movie clip by selecting the movie clip and opening the Object Actions panel.

ASSIGN ACTIONSCRIPT TO A MOVIE CLIP

onClipEvent (load) {

Actions

Ctrl+Alt+A

onClipEvent

⁄ Use

to select the movie clip.

¤ Click Window ➪ Actions to open the Object Actions panel.

■ The Object Actions panel appears.

‹ Click Actions.

› Double-click onClipEvent to select the onClipEvent action.

ˇ Click to select a handler („ changes to ´).

■ Use handlers to specify

when Flash should execute ActionScript.

29

FLASH ACTIONSCRIPT

ASSIGN ACTIONSCRIPT TO A FRAME

Y

ou can associate ActionScript with a frame. The actions execute when the playhead enters the frame. This is useful when you want to use ActionScript to initialize your variables, create a loop within a movie, or perform other tasks on entry into a frame. You must assign ActionScript to a keyframe. Keyframes mark changes in the action and store ActionScript. By default, the first frame in the Timeline is a keyframe. You create additional keyframes by selecting a frame and clicking Insert ➪ Keyframe from the menu. If you try to assign an action to a frame that is not a keyframe, Flash

automatically assigns the ActionScript to the previous keyframe on the Timeline. You should place frame actions on their own layer. Frames with actions in them display with a small a. For more on layers, see page 4. You can assign actions to a frame by clicking in a frame to select it and then opening the Action panel. You use the Action panel to enter your ActionScript. If you select multiple keyframes, Flash dims the Action panel and you will not be able to enter your ActionScript.

ASSIGN ACTIONSCRIPT TO A FRAME

Layer

Keyframe

⁄ Click Insert ➪ Layer to create a new layer.

F6

■ A new layer appears above the active layers.

¤ Click to select a frame.

30

‹ Click Insert ➪ Keyframe to create a keyframe.

GETTING FAMILIAR WITH FLASH

1

Flash gives consecutive numbers to the frames in the Timeline. When you are referring to frames in ActionScript, labeling the frames is preferable to referring to a frame by a frame number. If you add frames to or remove frames from your movie, the frame numbers change, but a label associated with a frame remains the same. Put frame labels on their own layer. For more on layers, see page 4. To create a frame label, select the frame to which you want to assign a label, click Window ➪ Panels ➪ Frame to open the Frame panel, and then type a label name in the Label field.

gotoAndPlay (1);

Actions

Ctrl+Alt+A

› Click Window ➪ Actions

ˇ Click to select your

to open the Frame Actions panel.

actions.

■ Use the Frame Actions panel to enter your ActionScript.

31

FLASH ACTIONSCRIPT

PUBLISH MOVIES

P

ublishing your movie enables you to present it to your audience. You can present your movie in several formats including a Flash movie for the Web; a GIF, JPEG, PNG, or QuickTime animation; an HTML document; or as a stand-alone executable for Windows or Macintosh. You use the Publish Settings dialog box to publish your movie. You select the formats. Flash assigns a default file name. You can use the default name or you can assign a filename. When publishing your movie for the Web, you can set several options including the order in which the layers load. The Load Order option controls which layer Flash Player draws first when the user plays the movie over a slow modem or network connection. Additionally, you can select the following options: Generate Size Report, Omit Trace Actions, Protect from Import, and Debugging Permitted.

Selecting Generate Size Report creates a TXT file containing detailed information on the size of each frame, scene, and object in your movie. Omit Trace Actions causes Flash to ignore any trace actions included your movie. For more information on trace actions, see Chapter 13. When you save your movie, Flash assigns the movie an FLA extension. You can modify an FLA file. When you publish your movie as a Flash movie for the Web, Flash assigns the movie an SWF extension. Protect from Import prevents others from importing your SWF file and converting it to an FLA file. Debugging Permitted allows the activation of Debugger. If you select this option, you can require a password for its use. See Chapter 13 for more information on debugging. A JPEG Quality slider is also available and enables you to adjust the quality of JPEG graphics — the higher the quality the larger the file size.

PUBLISH MOVIES

Publish Settings...

Ctrl+Shift+F12

⁄ Click File ➪ Publish Settings to open the Publish Settings dialog box.

■ The Publish Settings dialog box opens.

¤ Click in the Type Boxes to

› Click Use Default Names

select file types ( to ).

to use the default filenames.

changes

‹ Type in the Filename field to change the filename.

32

ˇ Click the Flash tab to set the options for the SWF file.

GETTING FAMILIAR WITH FLASH

To have your Flash movies load quickly, you want to keep your file size as small as possible. Sounds can increase file size significantly. You can adjust the sample rate and compression of a sound to reduce the file size. The lower you set the sample rate and compression, the lower the quality of sound, and the smaller the size of your file. You may want to experiment to obtain a suitable tradeoff between sound quality and file size. When creating an HTML document to display a Flash movie, you use the object and embed tags. Internet Explorer uses the object tag on Windows, while the embed tag is used by Netscape Navigator on Windows and the Macintosh and by Internet Explorer on the Macintosh. Internet Explorer for Windows uses ActiveX to play Flash content, while all other browsers use the Flash plugin.

If you change the width and height of your movie, you can use the Scale option to place the movie in the Web browser. Selecting default will display your movie within the boundaries you specify, maintaining the original aspect ratio. Selecting No Border will display your movie within the boundaries you specify; however, Flash will crop the movie, if necessary. Selecting Exact Fit will place the movie within the boundaries you specify, but will not maintain the original aspect ratio. Selecting this option may cause distortion.

Bottom Up

■ The Flash option screen appears. Á Click

to set the Load

Bottom Up

° If you selected Debugging

‚ Click to override current

— Click Set to open the

Permitted, enter a password if you want.

sound setting.

Sound Setting dialog box for Stream or Event sounds.

Order.

· Set the JPEG Quality using

‡ Click to select the

the JPEG Quality slider.

Generate Size Report, Omit Trace Actions, Protect from Import, or Debugging Permitted options.

1

CONTINUED

33

FLASH ACTIONSCRIPT

PUBLISH MOVIES (CONTINUED) f you did not specify the sample rate and compression for sound files using the Sound Properties dialog box, you can set them in the Publish Settings dialog box or you can use the Publish Settings dialog box to override previous settings. Use Audio Stream to set the sample rate and compression for stream sounds. Use Audio Event to set the sample rate and compression for event sounds.

I

the Publish Settings dialog box, provides you with a description of each of the templates.

You can select the version of Flash for which you want to publish your movie. Actions available in Flash 5 may not be available in earlier versions. To play your movie in a Web browser, the movie must be part of an HTML document. Selecting HTML as the format in the Publish Settings dialog box creates an HTML document that includes your Flash movie.

The Publish Settings dialog box contains four playback options. You can pause the movie until the user presses a button or selects play from the shortcut menu. You can have the movie loop when it reaches the last frame. You can display a shortcut menu when the user right-clicks in Windows or control-clicks on a Macintosh. And, in Windows, you can use device fonts if the font you selected is not available on the system of the user.

Flash provides you with several templates you can use to create your HTML document. Pressing the Info button, in

The Publish Settings dialog box also has options that enable you to set the quality, window mode, alignment, and scale.

In your HTML document, you can have the size of the movie match the size of the movie you created, or you can specify the size in pixels or as a percentage of the original movie.

PUBLISH MOVIES (CONTINUED)

Bottom Up

■ The Sound Settings dialog

¡ Click

box appears.

button to select a Sample Rate.

± Click

™ Click OK to close the

to select a Compression type.

34

dialog box.

£ Click

to select the version of Flash for which you are authoring.

¢ Click the HTML tab to display the HTML options.

GETTING FAMILIAR WITH FLASH

1

You can use the code shown here to manually add a Flash Movie to an HTML document.

= 5000 ) { setProperty (_root.stopMC, _visible, true); } }

USING GET TIMER AND GET VERSION

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file vertimer.fla, which you can find on the CD that accompanies this book.

212

¤ Click

to open the Actions panel.

ˇ Move to the test

‹ Get the timer using the

Note: See page 38 for instructions on how to test your movie.

getTimer function.

› Get the version using the getVersion function.

environment.

■ The screen displays the timer and version.

DEMYSTIFYING FUNCTIONS

9

USING EVAL

Y

ou use the ActionScript eval function to retrieve a variable, property, object, or movie clip from a string. This function is particularly useful when you have concatenated strings to form the variable, property, object, or movie clip name. The syntax for the eval function is eval(expression); . Use the expression argument to specify the variable property, object, or movie clip you want to retrieve. If the expression argument represents a variable or property, eval returns a value. If the expression argument represents an object or movie clip, eval returns a reference to the object or movie clip. If ActionScript cannot find the expression the argument represents, eval returns undefined.

The table that follows illustrates the eval function.

EXAMPLE

RETURNS

eval("sampleMC"); set ("x" + 1, 100); b = eval ( "x" + 1 ); eval("sampleMC._visible"); soundObj = new Sound( ); soundObj.attachSound( "music" ); soundObj.start( ); d = eval("soundObj");

_level0.sampleMC 100 true [object Object]

Flash 4 used the eval function to simulate arrays. If you are authoring for a Flash 5 environment, use the Array object to create arrays. USING EVAL

⁄ Select the frame, button,

‹ Increment the value of x

Á Move to the test

‡ Click the button to test

or movie clip to which you want to add ActionScript.

by one.

environment.

your movie.

› Assign a random number

Note: See page 38 for instructions on how to test your movie.

■ Clicking the button

Note: This example uses file eval.fla, which you can find on the CD that accompanies this book.

to a variable.

ˇ Retrieve the values.

retrieves the value assigned to the variable and the variable name.

¤ Click to open the Actions panel.

213

FLASH ACTIONSCRIPT

CONVERT A STRING TO A NUMBER

Y

ou cannot perform mathematical calculations using a string even if the value contained in the string is a number. If you need to perform a mathematical calculation using a value contained in a string, you must convert the string to a number.

function ignores blank spaces preceding a string. If the first character in the string is not a number, parseFloat returns NaN, which stands for not a number.

You can use the number function to convert a string to a number. You can also use the number function to convert a Boolean to a number. The Boolean true returns 1 and the Boolean false returns 0. The syntax for the number function is Number(expression); .

parseFloat(string); .

Use the expression argument to specify the string or Boolean you want to convert. For more information on the number function, see Chapter 4. You can also use the parseFloat function to convert a string to a number. The parseFloat function converts a string to a floating-point number. A floating-point number is a number that contains decimal places. If the string contains both numeric and non-numeric characters, the parseFloat function starts at the left and converts each character until it reaches the first non-numeric character. The parseFloat

The syntax for the parseFloat function is

Use the string argument to specify the string you want to convert. In addition to the parseFloat and number functions, you can also use the parseInt function to convert a string to a number. The parseInt function converts a string to an integer. An integer is a number that does not contain decimal places. The syntax for the parseInt function is parseInt(expression, radix); . Use the expression argument to specify the string you want to convert. Use the radix argument to specify the base from which you want to convert the string. Valid values are 2 to 36. The parseFloat function returns the value in base 10.

CONVERT A STRING TO A NUMBER

USING THE NUMBER FUNCTION

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file tonumber.fla, which you can find on the CD that accompanies this book.

214

¤ Click

to open the Actions panel.

USING THE PARSEFLOAT FUNCTION

‹ Convert a string to a

› Select the frame, button,

number using the number function.

■ Associating the variable

or movie clip to which you want to add ActionScript.

with a dynamic text box enables you to display the value the variable returns to the user.

ˇ Convert a string to a

■ Associating the variable

number using the parseFloat function.

with an input text box enables you to accept user input.

DEMYSTIFYING FUNCTIONS

9

You normally count 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and then you add a new column to form the number 10. You count in base 10. You work with 10 digits. You can count in other bases. For example, you can count in base 2. When you count in base 2, you only have two digits with which to work — 0 and 1. You start a new column after you use the second digit. The table shown here illustrates: BASE TEN

BASE TWO

0

0

1

1

2

10

3

11

4

100

5

101

6

110

7

111

COMMENTS

Using base two, you are out of digits. Form a new column. You are out of digits again. Form a new column.

You can use the parseInt function to enter a number in a base other than 10 and return a base 10 value. Use the radix argument to specify the base of the number you are entering.

USING THE PARSEINT FUNCTION

Á Select the frame, button, or movie clip to which you want to add ActionScript.

‡ Convert the string to a number using the parseInt function.

■ Associating the variables

with a dynamic text box enables you to display the value the variable returns to the user.

■ Associating the variables with an input text box enables you to accept user input.

° Move to the test

‚ Click the buttons to test

environment.

your movie.

Note: See page 38 for instructions on how to test your movie.

■ The script applies the

· Type values in the text boxes.

number, parseFloat, and parseInt functions to your entries.

215

FLASH ACTIONSCRIPT

EVALUATE FOR MATHEMATICAL ERRORS

Y

ou cannot perform mathematical calculations using non-numeric values. If you try to perform a mathematical calculation using a non-numeric value, ActionScript will return an error message. When you request information from the user, the user may enter a non-numeric value when a numeric value is required. You can use the isNAN function to test whether a value is numeric or non-numeric. If a value entered by the user is non-numeric, when a numeric value is required, you can send a message requesting that the user enter a number. The syntax for the isNAN function is isNaN(expression);. Use the expression argument to enter the expression you want to evaluate to determine if it is a number. The isNAN function returns true if the expression is not a number and it returns false if the expression is a number. When an expression returns infinity, that can be an indication of a mathematical error. For example, when you divide by 0, the result is infinity. You can use the

isFinite function to test whether an expression returns infinity. The syntax for the isfinite function is isFinite(expression). Use the expression argument to specify the expression you want to test. The isFinite function returns true if the expression is not equal to infinity and false if the expression is equal to infinity. The isFinite expression also returns false if the expression is equal to negative infinity or positive infinity. ActionScript defines negative infinity as any value that is smaller than the smallest value ActionScript can represent. Positive infinity is any value that is larger than the largest value that ActionScript can represent. The smallest value ActionScript can represent is approximately 5e324. The largest value ActionScript can represent is approximately 1.7976931348623158e+308.

EVALUATE FOR MATHEMATICAL ERRORS

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file tonumber.fla, which you can find on the CD that accompanies this book.

216

¤ Click

to open the Actions panel.

‹ Determine if the values are numbers using the isNAN function.

■ Associating the variables

with input text boxes enables you to accept user input.

› Send an error message to the user if a value is not a number.

ˇ Set the results of the calculation to a blank space if a value is not a number.

■ Associating the variables

with dynamic text boxes enables you to display the values the variables return to the user.

Á Test for infinity using the isFinite function.

DEMYSTIFYING FUNCTIONS

9

You can test user entries to determine if they are numbers. In the example that follows, if all entries are not numbers, the script returns an error message. If all entries are numbers, the script calculates an age based on the entries made. Example: on (release) { if (isNaN(monthV) || isNaN(yearV) ||isNaN( DayV)) { errorMessage = “Please enter numbers.”; result = “ “; } else { monthU = monthV-1; birth = new Date( yearV,MonthU, DayV ); today = new Date(); age = Math.floor ( (((((today-birth)/1000)/60)/60)/24)/365); result = “You are “ + age + “ years old.”; errorMessage = “”; } }

‡ Send an error message to

· Perform the calculations if

— Move to the test

¡ Click the button to test

the user if the expression returns infinity.

there are no errors.

environment.

your movie.

‚ Set the error message to a

Note: See page 38 for instructions on how to test your movie.

■ ActionScript will display

° Set the results of the calculation to a blank space if the expression returns infinity.

blank space if there are no errors.

± Type the value in the input text boxes.

an error message if your entry in not a number or if the calculation evaluates to infinity.

217

FLASH ACTIONSCRIPT

CREATE A SCROLLABLE TEXT BOX

W

hen working with dynamic or input text boxes, you may have more text than will fit in the visible area of the text box. You can use ActionScript to create buttons or scroll bars that enable the user to scroll up or down the text box or move to a specified line.

ActionScript numbers each line in a text box sequentially. The first line is line number one. Variables that are associated with dynamic or input text boxes have a scroll and maxscroll property. The scroll property returns the topmost visible line number in the text box. You can set or retrieve this value. The maxscroll property returns the topmost visible line in the text box when the last line of text is visible. You can retrieve the maxscroll value, but you cannot set the maxscroll value. The syntax for the scroll property is variableName.scroll = x; . Use the variableName argument to specify the variable name associated with the text box. Use the x argument to specify the line number you want to assign to the scroll property. For example, if

you want the user to move to line one on the release of the mouse after pressing a button, use the syntax shown here: on (release) { text.scroll = 1; } To retrieve the scroll value, use the syntax scrollValue = variableName.scroll; . As the user scrolls through a text box, the Flash Player updates the variable scrollValue. The syntax for the maxscroll property is variableName.maxscroll; . Use the variableName argument to specify the variable name associated with the text box. The example shown here displays the last lines of text when the user releases the mouse after pressing a button: on (release) { text.scroll = text.maxscroll; }

CREATE A SCROLLABLE TEXT BOX

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file scroll.fla, which you can find on the CD that accompanies this book.

218

¤ Click

to open the Actions panel.

‹ Assign text to an input or dynamic text field.

■ In this example, text is the

variable name and the variable is associated with an input text box.

› Select the frame, button,

ˇ Set the scroll value to its

or movie clip to which you want to add ActionScript.

current value plus one.

■ The Actions panel will become active.

■ This part of this example uses a button.

■ Each time the user releases

the mouse after clicking the button, the text box will scroll down one line.

DEMYSTIFYING FUNCTIONS

9

You can use the script shown here to create a continuous scroll button. When you press the button, the text box scrolls until you release the button. Start by creating a button and attach the script shown here. Example: on (press) { var press = true; } on (release) { var press = false;

Convert the button to a movie clip. Select the button and click Insert ➪ Convert to Symbol to open the Symbol Properties dialog box. Type a symbol name in the Name field and select Movie Clip as the Behavior. Attach the script shown here to the movie clip. In this example, the variable text is the name of the text box. Example: onClipEvent (enterFrame) { if (press == true) { _root.text.scroll = _root.text.scroll + 1; } }

Á Select the frame, button,

‡ Set the scroll value to its

° Move to the test

· Click the buttons to test

or movie clip to which you want to add ActionScript.

current value minus one.

environment.

your movie.

■ Each time the user releases

Note: See page 38 for instructions on how to test your movie.

■ When you click the down

■ The Actions panel will

become active.

the mouse after clicking the button, the text box will scroll up one line.

button the text scrolls down. When you click the up button the test scrolls up.

219

FLASH ACTIONSCRIPT

CREATE A CUSTOM FUNCTION

A

function is a reusable block of code. You use arguments to pass values to a function. The function performs operations on the values passed to it and returns the results. ActionSctipt comes with several predefined functions. For example, the functions getProperty, getTimer, random, and getVersion are all predefined by ActionScript.

syntax for the return action is return expression; . Use the expression argument to define the value to return. The expression argument is optional.

You can create your own custom functions using the function action. The syntax for the function action is

function twoDigit (number) { return math.round(number * 100)/100; }

function functionName (a1, a2, ...aN){ statement(s) }; Use the functionName argument to name your function. Use a1 to aN to specify the arguments to pass to the function. Arguments are optional. Use the statement argument to define the operation the function performs.

The following is an example of a custom function that you can use to round a floating-point number to two digits and return the value

The name of the function is twoDigit. It takes one argument — number — and it returns the value of the number rounded to two digits after the decimal point. When using Normal mode, you use the evaluate action to include a custom function to your script. The evaluate action creates an empty line with a semicolon.

When creating a custom function, you use the return action to specify the value the function should return. The CREATE A CUSTOM FUNCTION

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file function.fla, which you can find on the CD that accompanies this book.

220

¤ Click

to open the Actions panel.

‹ Create a function.

› Select the frame, button, or movie clip to which you want to add ActionScript.

ˇ Use the function you created.

■ Associating the variable

with a dynamic text box enables you to display the value the variable returns to the user.

■ Associating the variable

with an input text box enables you to receive input from the user.

DEMYSTIFYING FUNCTIONS

You can call a function from any Timeline, including the Timelines of loaded movies. To call a function from another Timelime, precede the function with the target path using dot syntax. Example:

_root.sampleMC.twoDigit(123.456); It is a good practice to document your functions with comments. Include the input, outputs, and purpose of the function in your comments.

9

If you omit arguments during a function call, ActionScript passes the argument to the function as undefined. This can cause errors when you export your movie. If you send extra arguments during a function call, ActionScript ignores them. A function does not have to return a value. For example, you can create a function that initializes values.

When creating a function, it is a good idea to use local variables. The scope of a local variable is limited to the curly braces that enclose it. Using local variables in a function prevents other scripts in the movie from reading the variables. ActionScript treats arguments passed to a function as local variables.

Test Movie

Ctrl+Enter

Á Click Control ➪ Test

‡ Type a floating point

° Click the button to test

Movie to move to the test environment.

number with more than two digits after the decimal point.

your movie.

■ The function rounds the

number you entered to two digits.

221

FLASH ACTIONSCRIPT

VIEW THE HIERARCHY OF MULTIPLE MOVIES

Y

ou create Flash movies on a Timeline. ActionScript refers to the main Timeline as _level0. You create other levels when you use the loadMovie command to load SWF files. You assign newly created levels a level number. You can use any level number you want, but only one movie can be on a given level at a time. You can turn any Flash movie into a movie clip. You can embed a movie clip symbol within a Flash movie, and you can embed multiple instances of a movie clip symbol inside itself or other movie clips. Loaded movies can have movie clips on their Timeline. In addition, those movie clips can have movie clips on their Timelines. Flash Player organizes the movies and movie clips in your movie into a hierarchy, called the display list. Movie

Explorer enables you to view the display list while you are authoring a Flash movie. You can also view the display list in Debugger. The display list graphically represents the relationship between Timelines. If you make a change to a Timeline, your change will affect all of the Timelines on the Timeline that you change. Timelines can send messages to other Timelines. For example, one Timeline can tell another Timeline to stop playing, begin playing, or perform any other action. When you place a movie or movie clip on the Timeline of another movie or movie clip, they form a relationship. The movie or movie clip that you place on the Timeline is the child. The Timeline on which you place the movie or movie clip is the parent. Any change that you make to the parent will affect the child.

VIEW THE HIERARCHY OF MULTIPLE MOVIES

Layer 1

Movie Explorer

⁄ Click Window ➪ Movie Explorer.

222

Ctrl+Alt+M

Symbol Definition(s)

■ Movie Explorer opens, and the display list appears.

¤ Click Timelines.

to view nested

WORKING WITH MULTIPLE TIMELINES

The display list in Movie Explorer shows the hierarchy of the movie. You can use the display list to see a graphical representation of a movie and all the objects included in the movie. You will find Movie Explorer particularly useful when you are examining a movie developed by someone else. Movie Explorer provides you with a mechanisn that allows you to easily understand how a movie is put together.

Circle

■ The path to the selected item appears on the Status bar. ■ You can use the Find text box to search for items.

10

When using Debugger, you can view the display list. When viewing the display list in Debugger, the addition and removal of movies and movie clips display instantly. The display list in Debugger also presents a hierarchical representation of the movie.

Circle

■ You can use the Filtering

buttons to limit the categories of items Movie Explorer displays.

■ The pop-up menu appears.

Note: You can use the menu to navigate Movie Explorer, edit objects, or print the hierarchy.

‹ Click

to display the pop-up menu.

223

FLASH ACTIONSCRIPT

ASSIGN TARGET PATHS

F

lash defines a target path as the address of the Timeline you want to target. There are two types of target paths: absolute and relative. An absolutepath is a fixed address; it is always the same. A relativepath is not fixed. You determine the relative path based on the Timeline that calls the action. ActionScript bases both absolute and relative target paths on the movie hierarchy. You can view the movie hierarchy using the Movie Explorer display list. An absolute path address begins with the name of the level the targeted movie clip was loaded into and includes the name of each instance until it reaches the target instance. For example, if you place a movie clip with an instance name of redMC on the main Timeline, the absolute path to redMC would be _level0.redMC. If you add an instance named

triangleMC to the Timeline of the movie clip redMC, the absolute path to triangleMC would be _level0. redMC.triangleMC. There are two methods used to specify a target path: dot syntax and slash syntax. Dot syntax separates each item in the path with a dot — for example, _level0.redMC. triangleMC. Slash syntax separates each item in the path with a slash — for example, _level0/redMC/triangleMC. ActionScipt bases a relative path on the relationship between the controller Timeline and the target Timeline. You can only use a relative path to target objects on the same level. Use the alias _parent to refer to the parent of the current Timeline. When using slash syntax, you use .. to move up the hierarchy.

ASSIGN TARGET PATHS

Get Path Functions

Actions

Ctrl+Alt+A

targetPath

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file path.fla, which you can find on the CD that accompanies this book.

224

¤ Click Window ➪ Actions to open the Actions panel.

‹ Click ➪ Functions ➪ targetPath to select the targetPath Action.

WORKING WITH MULTIPLE TIMELINES

When using dot syntax, you can use the keyword this to refer to the current Timeline. You can use the _target property to return the target path in slash notation. The syntax for the _target property is instanceName._target;

Use the instance name argument to specify the movie clip for which you want the target path. You can use the targetPath function to return the target path in dot notation. The syntax for the target path functions is

10

You use _level followed by the level number to refer to the main timeline for a level. If you want to reference the main Timeline for level 5, you use _level5. If you want to reference to the main Timeline for level 0, you use _level0. You can also use _root to refer to the main Timeline. You use the _root property to refer to the main Timeline for the current level. For example, if you are on level 5 _root refers to the main Timeline for level 5. If you are on level 0, _root refers to the main Timelime for level 0.

targetpath(instanceName);

Here also, use the instanceName argument to specify the movie clip for which you want the target path.

› Type your expression. ■ This expression retrieves

the target path and assigns it to the variable path.

■ If you associate the variable with a dynamic text box, you can display the value the variable returns to the user.

ˇ Move to the test

Á Click the button to test

environment.

your movie.

Note: See page 38 for instructions on how to test your movie.

■ The targetPath function retrieves the target path.

225

FLASH ACTIONSCRIPT

LOAD AND UNLOAD MOVIES AND MOVIE CLIPS he loadMovie action enables you to play several movies or movie clips in concert or in sequence without closing Flash Player. Using the loadMovie action, you can easily change movies without opening a new Web page. The syntax for the loadMovie action is

T

unique instance name. The loaded movie will inherit the position, scale, and rotation properties of the targeted movie clip. If you want to replace a movie clip, use the target argument to specify the movie clip that the loaded movie clip replaces. The target argument is optional.

loadMovie(URL , target/location, variable);

Flash organizes movies into a hierarchy called levels. You use the _level property to specify the level. The syntax for the _level property is _levelN; . Use the N argument to specify the level number. The movie loaded at _level0 sets the frame rate, background color, and frame size for all other movies.

Use the URL argument to specify the absolute or relative URL of the SWF file that you want to load. Relative paths must be based on the location of the SWF file, and the URL must be in a subdomain of the current movie. When you are testing Flash movies, all SWF files must be stored in the same folder. You can use the loadMovie action to replace a movie clip with a Flash movie. The targeted movie clip must have a LOAD AND UNLOAD MOVIES AND MOVIE CLIPS

Basic Actions Layer 1

Actions

Ctrl+Alt+A

⁄ Select the frame, button,

¤ Click Window ➪ Actions

or movie clip to which you want to add ActionScript.

to open the Actions panel.

Note: This example uses file load.fla, which you can find on the CD that accompanies this book.

226

Load Movie

Esc+lm

‹ Click ➪ Basic Actions ➪ Load Movie to select the loadMovie Action.

WORKING WITH MULTIPLE TIMELINES

The loadMovie action enables you to break a large project down into its component parts and load each movie when needed. Several small movies play faster and use memory more efficiently than one large movie.

10

You can use this script to load a movie and send variables using the post method. Example: loadMovieNum ("sample.swf", 1, "POST");

You can use this script to replace a movie clip with a movie when the user releases the mouse after clicking a button. Note the location at which the loaded movie appears. Also note that if you rotate or scale the movie clip, the loaded movie inherits the properties. Example: on (release) { loadMovie ("redstar.swf", "blueStarMC"); }

› Type the URL of the movie that you want to load.

ˇ Click

and select the location where the movie will load.

■ To load a movie, select

Level. To load a movie clip, select Target.

Á Type a level number.

■ If you are replacing a

movie clip, type the target path instead of performing step 6.

‡ Click

° Move to the test

· Click the button to load

environment.

your movie.

Note: See page 38 for instructions on how to test your movie.

■ Your movie loads.

and select how you want to send variables.

■ You can choose from Don’t Send, Send Using Get, or Send Using Post.

CONTINUED

227

FLASH ACTIONSCRIPT

LOAD AND UNLOAD MOVIES AND MOVIE CLIPS (CONTINUED)

T

he main Timeline for every movie is located on _level0. When loading a movie, you can specify a level. You can use any level number that you want, but only one movie can be on a given level at a time. When loading a movie, use the location argument to specify the level into which you want to load the movie. When you load a movie into level 0, the new movie will replace the current movie, and all other levels will be unloaded. When you load a movie into a level occupied by another movie, the new movie will replace the movie at that level. When you load a movie into an unoccupied level, all existing movies will remain, and the new movie will be loaded. You can send variables to the CGI scripts using the loadMovie action. The Variable parameter in Normal Mode presents you with three choices: Send Using Get, Send Using Post, and Don’t Send. Use Send Using Get to append a small number of variables to the end of the URL.

Use Send Using Post to send variables separate from the URL. Send Using Post enables you to send a larger number of variables. Use Don’t Send if you do not want to send any variables. Use the variable argument to specify the method that you want to use to send associated variables. You use the unloadMovie action to remove a movie loaded using the loadMovie action. The syntax for the unloadMovie action is unloadMove(location); Use the location argument to specify the level of the target movie that you want to unload. When you select loadMovie in Normal Mode, Flash may substitute LoadMovieNum. For an explantion of LoadMovie and LoadMovieNum, see the appendix.

LOAD AND UNLOAD MOVIES AND MOVIE CLIPS (CONTINUED)

Basic Actions

Actions

Ctrl+Alt+A Unload Movie

⁄ Select the frame, button, or movie clip to which you want to add ActionScript.

Note: This example uses file load.fla, which you can find on the CD that accompanies this book.

228

■ This example uses a button.

¤ Click Window ➪ Actions to open the Actions panel.

Esc+um

‹ Click ➪ Basic Actions ➪ Unload Movie to select the unloadMovie Action.

WORKING WITH MULTIPLE TIMELINES

10

When you load a movie on another movie, the loaded move is aligned with the upper left corner of the movie into which it is loaded. To ensure proper alignment, it is a good idea to make both movies the same size.

The following example loads a movie. Example: loadMovieNum ("sample.swf", 1);

The following example unloads a previously loaded movie. Example: unloadMovieNum (1);

The following example replaces a movie clip with a movie. Example: loadMovie ("sample.swf", "sampleMC");

› Type a Level number.

ˇ Move to the test

Á Click the button to load

‡ Click the button to unload

environment.

your movie.

your movie

Note: See page 38 for instructions on how to test your movie.

■ Your movie loads.

■ Your movie unloads.

229

FLASH ACTIONSCRIPT

USING TELL TARGET

Y

ou can use the tellTarget action to send statements to a movie clip. You can also use tellTarget to send statements to a movie that was loaded using the loadMovie action. You assign the actions that you want the target movie or movie clip to perform to a frame, button, or movie clip. The frame, button, or movie clip to which you assign the actions is the controller. The movie or movie clip that receives the actions is the target. A targeted movie clip must have a unique instance name and must be on the Timeline of the movie on which you create the controller. The syntax for the tellTarget action is tellTarget(target){ statement; }

Use the target argument to specify the target path to be controlled. Use the statement argument to specify the statements that you want to send. You can use the Insert

Target Path dialog box to specify the target movie clip. To open the Insert Target Path dialog box, click the Insert Target Path button in the lower-right corner of the Actions panel. When using the Target Path dialog box, use the Notation radio buttons to specify the type of notation that you want to use. You can choose from dot and slash. The default notation type is dot. You use the Mode radio buttons to specify the mode; you can choose Relative or Absolute. The default mode is Relative. If you choose the Relative mode, the tree view displays only movie and movie clip instances that are located on the controller Timeline and their children. You can use the keyword this to refer to the current Timeline. If you choose the Absolute mode, the tree view displays all the loaded movies and movie clips and uses _level or _root to designate their location.

USING TELL TARGET

Basic Actions Start Movie

Actions

Ctrl+Alt+A Tell Target

⁄ Select the frame, button, or movie clip to which you want to add ActionScript.

Note: This example uses file telltarget.fla, which you can find on the CD that accompanies this book.

230

¤ Click Window ➪ Actions to open the Actions panel.

Esc+tt

‹ Click ➪ Basic Actions ➪ Tell Target to select the tellTarget Action.

■ If you want to open the

Target Path dialog box, click the Insert Target Path dialog box.

WORKING WITH MULTIPLE TIMELINES

Before you can tartget a a Timeline, the Timeline must be in Flash Player. You cannot target the Timeline of a movie or movie clip that is not loaded. If you are targeting a movie clip, the playhead must be located in one of the frames of the movie clip. If the movie clip is in frames 1 to 10 and the playhead is in frame 11, you cannot target the movie clip.

10

Flash 5 deprecated the tellTarget action. You should use the with action when you are authoring for a Flash 5 environment.

› Type a Level number. ˇ Type your statements.

Á Move to the test environment.

‡ Click the button to load

° Click the button to start

your movie.

your movie

■ Type the actions you want

Note: See page 38 for instructions on how to test your movie.

■ Your movie will load.

■ Your movie will start.

to execute.

231

FLASH ACTIONSCRIPT

USING THE WITH ACTION

Y

ou can use the with action instead of the tellTarget action to send statements to movie clips and to movies that have been loaded with the loadMovie command. As when using the tellTarget action, you assign the actions that you want the target movie to perform to a frame, button, or movie clip. The frame, button, or movie clip to which you assign the actions is the controller. The movie or movie clip that receives the actions is the target. The with action is preferable to the tellTarget action because Flash 5 deprecated the tellTarget action. In addition, the with action has a few advantages over the tellTarget action. For example, the with action can take a movie clip or other object as a target. When you use the tellTarget action, you must specify a target path, and the tellTarget action cannot target objects. As with the tellTarget action, you can use the with action to perform multiple actions on the same target. The syntax for the with action is

with(object) { statement(s); } Use the object argument to specify the movie, movie clip, or object on which you want to execute the statements. Use the statement argument to specify the statements that you want to execute. ActionScript uses the following order to determine the scope of the with action: 1) the objects under the innermost with action, 2) the objects under the outermost with action, 3) the activation object (the activation object is an object that ActionScript creates automatically when you call a function; it holds the local variable called by the function), 4) the movie clip that contains the script that you are executing, and 5) global objects such as Math and String.

USING THE WITH ACTION

Actions Start Movie

Actions

Ctrl+Alt+A

with

⁄ Select the frame, button, or movie clip to which you want to add ActionScript.

Note: This example uses file with.fla, which you can find on the CD that accompanies this book.

232

¤ Click Window ➪ Actions to open the Actions panel.

Esc+wt

‹ Click ➪ Actions ➪ with to select the with Action.

WORKING WITH MULTIPLE TIMELINES Using the with action, the following script adjusts the _xscale, yscale, and _alpha properties of the block movie clip when the user releases the mouse after clicking a button.

10

Using standard syntax, the following script adjusts the _xscale, yscale, and _alpha properties of the block movie clip when the user releases the mouse after clicking a button.

Example: on (release) { with (block) { _xscale = 50; _yscale = 75; _alpha = 40; } }

Example: on (release) { block._xscale = 50; block._yscale = 75; block._alpha = 40; }

Using the tellTarget action, the following script adjusts the _xscale, yscale, and _alpha properties of the block movie clip when the user releases the mouse after clicking a button: Example: on (release) { tellTarget ("block") { _yscale = 75; _xscale = 50; _alpha = 40; } }

› Type a level number if you are targeting a movie loaded with the loadMovie action or type a target path if you are targeting a movie clip.

ˇ Type your statement(s). ■ Type the statements you want to execute.

Á Move to the test environment

Note: See page 38 for instructions on how to test your movie.

‡ Click the button to load your movie.

■ The movie will load.

° Click the button to start your movie

■ The movie will start.

233

FLASH ACTIONSCRIPT

DUPLICATE MOVIE CLIPS

I

ActionScript does not copy the variables in the parent movie clip to the child movie clip. If you delete the parent movie clip, ActionScript will automatically delete the child.

duplicateMovieClip(target, newName, depth);

ActionScript places the child movie clip directly on top of the parent. You can use the _x and/or _y properties to change the location of the duplicated movie clip. Each instance of the duplicated movie clip must have a unique name. You can append an incrementing number to the end of the movie clip name to make each instance unique.

f you want to make a copy of a movie clip that is currently on the Stage, use the duplicateMovieClip action. The duplicateMovieClip action enables you to create a new instance of a movie clip while the movie is playing. The syntax for the duplicateMovieClip action is

Use the target argument to specify the name of the instance that you want to duplicate. Use the newName argument to specify the name that you want to give to the new instance. The depth argument is used to specify stacking order. Stacking order determines how objects appear on the Stage when objects overlap. Objects with a higher depth number appear to be in front of objects with a lower number. Assign each object that you duplicate a depth number. If you place a new instance on the same depth level as an existing instance, the new instance replaces the existing instance. Duplicated movie clips always begin playing in frame 1.

You use the removeMovieClip action to remove instances created with the duplicateMovieClip action. The syntax for the removeMovieClip action is removeMovieClip(target); Use the target argument to specify the movie clip that you want to remove. You can also use the removeMovieClip action to remove movie clips created with the attachMovie and duplicateMovie methods.

DUPLICATE MOVIE CLIPS

⁄ Click

to open the Action panel.

¤ Select the frame, button, or movie clip to which you want to add ActionScript.

Note: This example uses file duplicate.fla, which you can find on the CD that accompanies this book.

■ This part of this example uses a button.

‹ Duplicate the movie clip. › Reset the _x property for the new instance so that the new instance does not appear on top of the existing instance.

■ Each time the user clicks the Duplicate button, the new duplicate instance replaces any existing duplicate instance.

ˇ Select the frame, button, or movie clip to which you want to add ActionScript.

234

WORKING WITH MULTIPLE TIMELINES Using the following script, you make the movie clip that you are going to duplicate draggable. You start by attaching the script shown here to a button to make the button draggable, and then you click Insert➪Convert to Symbol to convert the button to a movie clip. You name the movie clip redDotMC. Example: on (press) { startDrag (redDotMC); } on (release) { stopDrag (); }

10

Assign the following code to a button. The statement copyMC = "newDot" + i; concatenates the current value of i with newDot and assigns the result to the variable copyMC. The statement i = i + 1 increments the value of i by 1. This ensures that each instance of the duplicated movie clip has a unique name. You use the set property action to place the duplicate next to the original. Unless the user drags the duplicate to a new location, each new copy will be stacked on the previous copy. Example:

You can use the script that follows to duplicate a movie clip. Assign the following code to frame 1 to initialize i to 1. You use i to set the depth and to ensure that each instance of the duplicated movie clip has a unique name:

on (release) { copyMC = "newDot" + i; duplicateMovieClip (redDotMC, copyMC, i); setProperty (copyMC, _x, redDotMC._x +100); i = i + 1; }

i = 1;

Á Remove the movie clip. ‡ Move to the test environment.

Note: See page 38 for instructions on how to test your movie.

° Click the button to duplicate your movie clip. ■ A duplicate of your movie clip will be created.

· Click the button to remove the duplicate movie clip.

■ The duplicate of your

movie clip will be removed.

235

FLASH ACTIONSCRIPT

CREATE SMART CLIPS

A

smart clip is ActionScript that designers can reprogram without using the Action panel. Smart clips enable you to create ActionScript that people with no programming ability can modify. You define a list of options that affect the movie clip look or behavior. Designers select from those options. You start the creation of a smart clip by creating a movie clip. Include any values you want the smart clip to pass to the movie clip as variables in the movie clip. You define smart clips in the Define Clip Parameters dialog box, which you can find by selecting Define Clip Parameters from the Options menu of the Library. In the Define Clip Parameters dialog box, you use the button to add new parameters and values. You use the button to

remove parameters and values. You use the buttons to change the order of parameters.

and

The Define Clip Parameters dialog box enables you to add the values from which the designer can choose. You specify a value type of Default, Array ,List, or Object. Default enables you to default the value the designer can select to a string or number. Array enables you to provide the designer with a list of values from which he can choose. The designer can add or remove values from the list. List enables you to create a list of values that the designer can choose from but cannot modify. The Object type enables you to declare several related elements and specify the names and values. For example, you can use the Object type to specify the elements in an array.

CREATE SMART CLIPS

Background

Library

⁄ Create a movie clip. Note: This example uses file smartclip.fla, which you can find on the CD that accompanies this book.

236

¤ Include variables that the user can set in your script.

Note: A parameter is a variable.

‹ Click Window ➪ Library to open the Library panel.

Ctrl+L

› Click to select the movie clip in the Library.

CREATING SMART CLIPS

When you place a movie clip in the Library, it is available only to that movie. You can use the common library to make a movie clip available to all movies. Because smart clips are reusable code, it is a good idea to place them in the common library.

11

You use smart clip parameters to change the behavior or appearance of a movie clip. Smart clip parameters are passed to the movie clip when the movie clip loads. Smart clips display a unique icon in the Library window.

To add a file to the common library, copy the file to the Libraries folder under the Flash application folder. To use the file, click Window ➪ Common Libraries and select the file from the submenu. Drag the file from the common library onto the Stage.

Define Clip Parameters...

ˇ Click Options ➪ Define Clip Parameters to open the Define Clip Parameters dialog box.

Á Click

to add a

° Double-click Value to

parameter.

open the Values panel.

‡ Double-click here and

· Double-click here and

type a variable name.

select a type. CONTINUED

237

FLASH ACTIONSCRIPT

CREATE SMART CLIPS (CONTINUED) ou enter notes in the Description field of the Clip Parameters panel. You can enter any information you want in this field. The Clip Parameters panel has a Lock in Instance box. The Lock in Instance field prevents the user from renaming parameters. It is a good idea to check this box.

Y

Let us say you have a movie clip. Sometimes the designer wants the movie clip to play with a blue background. At other times, he wants the movie clip to play with an orange or black background. You can create a smart clip that allows the designer to select the hexadecimal code for the background color he wants to use.

A smart clip parameter is a variable. When you create or modify your movie, you define the variables. The designer uses the Clip Parameters panel to select parameter values. Selecting a parameter value assigns a value to the variable.

You start by creating ActionScript that will change the background color, including a variable that defines the color. Enter the name of the variable that defines the color in the Name field of the Define Clip Parameters box. Use the Value field to list the possible values.

You can use smart clips for any repetitive programming tasks. For example, you can create menus, buttons, list boxes, logos, games, or other types of movie clips and use smart clips to change or modify them.

When the designer opens the Clip Parameters panel, he will be able to select the hexadecimal code he wants to use from the list you provide.

CREATE A SMART CLIP (CONTINUED)

Panels

Background

0x000000

Clip Parameters

‚ Click to add a value. — Double-click here and type a value.

238

± Click OK. ¡ Click OK.

™ Select the movie clip. ■ Select the black background.

£ Click Window ➪ Panels ➪ Clip Parameters to open the Clip Parameters panel.

CREATING SMART CLIPS

A smart clip custom interface enables you to pass values to a movie clip using a movie instead of the Clip Parameters panel. If you create a custom interface, when the designer selects Window ➪ Panels ➪ Clip Parameters from the menu, Flash presents the custom interface instead on the Clip Parameters panel. The designer makes selections from the custom interface.

11

It is a good practice to save the custom interface SWF file and the FLA for the smart clip that uses it in the same directory. If you use your smart clip in multiple files, the SWF file for the custom interface and the FLA for the smart clip should always be in the same relative location. If you place your custom smart clip in the common library, you must copy the SWF to the Libraries folder with the same relative path that you specified in the Define Clip Parameters dialog box.

Background

0xff9966

¢ Click

to select a value.

■ You can use your smart

clip to select a background color for your movie.

∞ Move to the test

§ Your movie plays

environment.

automatically when you enter the test environment.

Note: See page 38 for instructions on how to test your movie.

■ The background of the

movie appears in the color you selected in the Clip Parameters panel.

239

FLASH ACTIONSCRIPT

CREATE A SMART CLIP CUSTOM INTERFACE

A

smart clip enables you to create ActionScript that a designer can reprogram without using the Actions panel. The designer uses the Clip Parameters panel to select from a list of options you set up. You can create a custom interface for a smart clip. A custom interface enables you to pass values to a movie clip using a movie instead of the Clip Parameters panel. Using a custom interface, you can create smart clips that are user friendly and aesthetically pleasing. You start by creating a movie that will act as the interface. The movie should provide the user with options that can be used to select the values the user wants to set. You pass the values to the smart clip using an intermediary, or exchange, movie clip. An intermediary movie clip contains nothing. It is completely blank. You do not place any graphics, buttons, movie clips, or ActionScript in an intermediary movie clip.

You use the Symbol Properties dialog box to create an intermediary movie clip. Simply specify a Name in the name field and select movie clip as the behavior. Intermediary movie clips have an instance name of xch. You must place an instance of the exchange movie clip on the main Timeline of the custom interface movie. Create a layer and name the layer Exchange Clip. See Chapter 1 for more information on creating layers. Place the intermediary movie clip in frame 1 of the Exchange Clip layer. The intermediary movie clip appears on the Stage as a small dot. Use the Instance panel to name the movie clip instance xch. The xch movie clip instance must always be loaded. You can pass arrays and objects through the xch movie clip, but you cannot pass nested arrays or objects.

CREATE A SMART CLIP CUSTOM INTERFACE

New Symbol... Custom Interfac

⁄ Create a movie to use as a custom interface.

Custom Interfac

Note: This example uses file colorsc.fla, which you can find on the CD that accompanies this book.

¤ Add statements that pass parameters to the xch movie clip.

240

Ctrl+F8

■ You must create the

intermediary movie clip with an instance name of xch. Do not place any graphics, buttons, movie clips, or ActionScript in the intermediary movie clip.

‹ Click Insert ➪ New Symbol to open the Symbol Properties dialog box.

› Type a name. ˇ Click Movie Clip to select it („ changes to ´).

Á Click OK.

CREATING SMART CLIPS

11

Flash ships with smart clips that you can use to create interactive learning applications. To find these smart clips, click Window ➪ Common Libraries ➪ Learning Interactions. The Learning Interactions smart clips enable you to create true/false, multiple choice, fill-in-the-blank, drag-and-drop, hot spot, and hot object learning applications. With the true/false smart clip, you can create applications with an either/or option. The multiple-choice smart clip enables you to create applications that allow the user to select from a list of options. The fill-in-the-blank smart clip enables you to create applications that allow the user to type in one or more responses. You can use the drag-and-drop smart clip to create applications that require the user to drag objects to a defined area. Use the hot-spot smart clip when you want the user to select one or more of the defined areas. Use hot object when you want the user to select one or more predefined objects.

Exchange Clip

Exchange Clip

Library

Ctrl+L

‡ Click to create a new

° Double-click and type

· Click Window ➪ Library

— Drag the intermediary

layer.

to name the layer Exchange Clip.

to open the Library.

movie clip from the Library onto the Stage.

Note: See page 4 for more information on layers.

‚ Click to select frame 1 of the Exchange Clip layer.

± Select the instance that you just dragged onto the Stage. CONTINUED

241

FLASH ACTIONSCRIPT

CREATE A SMART CLIP CUSTOM INTERFACE (CONTINUED)

P

arameters are variables that are included in statements in your custom interface movie. You use parameters to pass values to the xch movie clip. In Normal mode, you can use the set variable action to set the variable. The following is an example:

If you want a smart clip that can change the background color of a movie clip, you can create a smart clip that allows the user to select the hexadecimal code for the background color from a list in the Clip Parameters panel. Unfortunately, hexadecimal codes are not user friendly. You can create a custom smart clip that enables the user to click on the background color they want to use.

_root.xch.colorV = parseInt(0x000000); The example sets the value of a variable named colorV. Note that the intermediary movie clip is included in the path name. Place your statements that pass parameters in the custom interface movie. When you complete your custom interface movie, publish it as an SWF file.

Start by creating a movie that will act as the custom interface. The movie should include options that allow the user to select a color. Use a variable to pass the selection to the xch movie clip. Place the exchange movie clip on the Stage. In the movie that uses the custom smart clip, use the UI field of the Define Clip Parameters dialog box to link to the custom smart clip.

In the movie that uses the custom interface, you link the smart clip to the movie using the Define Clip Parameters dialog box. Place the path to the smart clip in the Link to Custom UI field.

CREATE A SMART CLIP CUSTOM INTERFACE (CONTINUED)

Exchange Clip Panels

Library

Instance

Ctrl+I

¡ Click Window ➪ Panels ➪ Instance to open the Instance panel.

™ Type xch to name the instance.

242

Ctrl+L

£ Publish your movie as an SWF file. Note: See page 32 for information on how to publish your movie.

¢ Open the movie with which you want to associate the smart clip.

∞ Click Window ➪ Library

Note: This example uses smartclip2.fla, which you can find on the CD that accompanies this book.

with which you want to associate the custom movie clip.

to open the Library.

§ Click to select the movie

¶ Click Options.

CREATING SMART CLIPS

Learning Interactions includes a feature called Knowledge Track. Knowledge Track allows you to send data to a learning management system. You can use Lotus LearningSpace, or another tracking system. Knowledge Track uses AICC (Aviation Industry CBT Committee) specification version 2.0, an industry standard protocol for courseware-to-tracking system communications. You can set the following values: interactionID, ObjectiveID, and Weighting.

11

To include Learning Interactions Library smart clips in your movie, select a keyframe. Then click Window ➪ Common Libraries ➪ Learning Interactions and drag a Learning Interactions smart clip onto the Stage. Then click Window ➪ Panels ➪ Clip Parameters to open the clip parameters panel. If you select TrueFalse, you can use the clip parameters panel to define your question, select the correct answer, and specify the feedback you want to send to the user. A navigation tab enables you to specify how you want Flash to navigate.

Background

Panels

Clip Parameters

Define Clip Parameters...

• Click Define Clip

ª Associate the smart clip

– Select the movie clip with

‘ Click a color to select an

Parameters to open the Define Clip Parameters dialog box.

with the movie.

which you associated the custom smart clip.

option.

º Click OK.

≠ Click Window ➪ Panels ➪ Clip Parameter to open the Clip Parameters dialog box.

■ When the Clip Parameters panel opens, you can select options using the custom smart clip.

243

FLASH ACTIONSCRIPT

VALIDATE A STRING

A

n important part of collecting information from the user is validating the data. Strings may need to be of a specific length or contain specific characters. For example, say that you require a user to enter a product code. In your organization, all product codes begin with the letter p, followed by a 10, 20, or 30, a dash, and a digit. The following is a valid product code: p20-1. In this situation, if the user submits an invalid product code, you have to contact the user to determine the correct code. You can instead validate user entries at entry to ensure that you do not receive any invalid codes. Many of the string functions are useful when validating data, and you can use them in coordination with one another to validate user entries.

The product code in the preceding example must be exactly five characters long. You can use the String length method to determine the length of the string. The first character of the product code must be a p. You can use the substring method to retrieve the value to determine if the user entered the letter p. The next four characters must be 10, 20, or 30, a dash, and a digit. Again, you can use the substring method this time used with an or to determine if the user entry is valid. You can retrieve the last character of the entry and use the isNaN function to determine if it is a number. After you evaluate whether an entry is valid, if the user enters an invalid entry, you can use a dynamic text box to send a message that tells the user what the valid entries are and instructs the user to enter a valid entry.

VALIDATE A STRING

Actions

Ctrl+Alt+A

⁄ Select the frame, button,

¤ Click Window ➪ Actions

or movie clip to which you want to add ActionScript.

to open the Actions panel.

Note: This example uses file valstring.fla, which you can find on the CD-ROM that accompanies this book.

244

‹ Use the length function to determine if the user has made an entry.

■ This makes the input check

› Check the value of a

input.

substring, convert the input to lowercase, and compare it to a lowercase value.

insensitive to case.

ˇ Check the length of the

USING CREATIVE TECHNIQUES

12

When validating data, you may need to determine whether the user made an entry. You can make this determination by checking the length of the input field. If the length of the field is 0, the user has not made an entry.

If the user is required to enter a code with a delimiter such as a dash, for example, product code p10-9, you can have the user make the entry without the delimiter, and you can use code similar to the following to add the delimiter later.

Example:

Example:

if (length(input) == 0) { errorMessage = "Please enter a product code.";

input = input.substring(0,3) + "-" + input.substring( 3,4);

If you do not want to take case into consideration when you evaluate an entry made by the user, use the toLowerCase or toUpperCase function to convert the input value before you make your comparison. The example shown here converts the input to lowercase and then compares the input to a lowercase value.

When validating a list of values, you may want to use a custom function. See Chapter 9 for more information on custom functions.

Example: if (input.toLowerCase().substring(0, 1 ) != "p")

Á Check a substring to ensure that the input value is in a valid list of values.

‡ Check a substring to ensure that the value is a number.

° Send error messages to the user.

· Move to the test environment.

‚ Test your movie by first

■ Associate the variable with

Note: See page 38 for instructions on how to test your movie.

— Click the Submit button.

a dynamic text box. This enables you to display the value that the variable returns to the user.

entering a product code.

■ The script validates user entries.

245

FLASH ACTIONSCRIPT

VALIDATE A DATE

T

he 12 months of the year are usually numbered from 1 through 12, starting with January. With ActionScript, if you enter 20 as the month, it will accept your entry as a valid entry. It will also accept an invalid number for the number of days in a month, and years are not limited to four digits. You can enter more than the 24 hours in a day, the 60 minutes in an hour, the 60 seconds in a minute, and so on. Therefore, when a user enters a date or time value, you may want to validate the value to ensure that the user has entered valid data. You want to make sure that the value the user enters for the month is a number between 1 and 12 and that the number of days entered for the months April, June, September, and

November do not exceed 30. February is limited to 28 days, and you want to account for Leap Year. The remaining months cannot have more that 31 days. If the user is entering a time, you want to do similar time validations. These validations require conditional checking. If the month is equal to 1 (January), the day must be greater than 0 but less than 32, but if the month is equal to 4 (April), the day must be greater than 0 but less than 31. It is even more complicated for February; the day cannot be greater than 28 unless the year is a Leap Year. You can use the modulo operator to help you determine whether the year is a Leap Year.

VALIDATE A DATE

Actions

Ctrl+Alt+A

⁄ Select the frame, button,

¤ Click Window ➪ Actions

‹ Validate the month.

ˇ Check whether the user

or movie clip to which you want to add ActionScript.

to open the Actions panel.

› Validate the day.

made an entry.

Note: This example uses file birth.fla, which you can find on the CD-ROM that accompanies this book.

246

USING CREATIVE TECHNIQUES

When validating dates, you must keep the following in mind: A Leap Year occurs whenever the year is evenly divisible by four, unless the year is also divisible by 100. However, if the year is evenly divisible by 100 and evenly divisible by 400, it is a Leap Year. The modulo operator returns the remainder of one number divided by another number. Because you begin determining whether a year is a Leap Year by finding out if the year is evenly divided by four, you should use the modulo function. Your expression will look similar to the one shown here. Example:

12

If you do a lot of date checking, you will definitely want to develop custom date-checking functions, such as the following. The function returns true if the month argument is between 1 and 12 and false if it is not. See Chapter 9 for more information on custom functions. Example: function validateMonth (month) { if (month < 1 || month > 12 ) { return false; } else { return true; } }

year % 4 ==0

The operator divides the number 4 into the value in the variable year and returns the remainder. The expression shown tests to determine if the remainder is equal to 0.

Á Send error messages.

‡ Perform a calculation.

° Move to the test environment. Note: See page 38 for instructions on how to test your movie.

‚ Click the Submit button. ■ The script will validate

your entry before calculating your age.

· Test your movie by entering your birthday.

247

FLASH ACTIONSCRIPT

SEARCH A TEXT BOX

Y

ou can use the Selection.setFocus method with the Selection.setSelection method, String.indexOf method, and length property to add a search feature to a text box. A search feature enables the user to search a text box for a word or phrase. The user types the word or phrase into an input text box and clicks a button, and ActionScript finds and selects the word or phrase entered, or it sends a message to the user stating the entry cannot be found. You can search a text box from top to bottom or from bottom to top. The Selection.setFocus method sets the focus to a specified text box. You must set the focus before you can use the Selection.setSelection method. The syntax for the Selection.setFocus method is Selection.setFocus(string) Use the string argument to specify a string that names the variable associated with the text box to which you want to set the focus.

Selection.setSelection(start,end); Use the start argument to indicate the index position at which you want to start the selection. Use the end argument to indicate the index position at which you want to end the selection. The first position in the text box has an index position of 0. The String.indexOf method searches a string for a specified value and returns the index position for that value. The syntax for the String.indexOf method is string.indexOf(value, start) Use the string argument to specify the string you want to search. Use the value argument to specify the value for which you want to search. Use the start argument to specify the index position at which you want your search to begin. If the String.indexOf method does not find the value specified, it returns -1.

The Selection.setSelection method selects an area in the text box that currently has focus. The syntax for the Selection.setSelection method is SEARCH A TEXT BOX

text = "George Bill Tom Peter Bill George Allen Fred Bill Fred Peter George

Actions

Ctrl+Alt+A

⁄ Select the frame, button,

¤ Click Window ➪ Actions

‹ Assign text to a variable.

ˇ Initialize the variable.

or movie clip to which you want to add ActionScript.

to open the Actions panel.

› Associate the variable

■ This example uses the

Note: This example uses file search.fla, which you can find on the CD-ROM that accompanies this book.

248

with a text box.

startV variable to specify where the search should start. The variable StartV is used as the indexOf start argument.

USING CREATIVE TECHNIQUES

12

If you do not want your search to be case sensitive, use a script similar to the one shown here. Apply the String.toLowerCase methods to the value for which you are searching and to the text you are searching. Example: on (release) { valueV = text.toLowerCase().indexOf(searchV.toLowerCase(), startV ) ; if (ValueV != -1) { Selection.setFocus("text"); Selection.setSelection(valueV,valueV + length(searchV.toLowerCase())); startV = valueV + 1; messageV = ""; } else { startV = 0; messageV = "End of text. Entry not found. Click again to start at beginning."; } }

Á Select the frame, button, or movie clip to which you want to add ActionScript.

‡ Get the indexOf search value and associate the variable with an input text box.

° Check to determine if the value of searchv is found.

· If ActionScript finds the search value, set the focus.

■ Use searchv to get the

value for which the user is searching.

CONTINUED

249

FLASH ACTIONSCRIPT

SEARCH A TEXT BOX (CONTINUED)

I

f you use the String.indexOf method as the start argument for the Selection.setSelection method, ActionScript will find the value that you specify and start a selection beginning where the value you are searching for begins. If you set the end argument to the start position plus the length of the value for which you are searching, ActionScript will select the value for which you are searching. You can use an if statement to determine whether the search will find a value. If the search will find a value, execute the search. Start the next search at the value returned by indexOf +1. This causes your script to

continue searching the text box until it does not find the value. If the search does not return a value, you can send a message to the user stating value not found. You then set the indexOf start value to 0. This will cause the next search to begin at the beginning of the text box. The search is case sensitive. If you type bill, the search will not find Bill. If you do not want your search to be case sensitive, either apply the String.toLowerCase or String.toUpperCase methods to the value for which you are searching and to the text you are searching. This forces the comparison of two values of the same case, regardless of what the user enters.

SEARCH A TEXT BOX (CONTINUED)

‚ Define the selection criteria.

— Use IndexV as the start argument for Selection .setSelection.

250

± Use indexV plus the length of the search criteria as the end argument for Selection .setSelection.

■ This causes the next

£ If ActionScript cannot find

¡ Add 1 to the indexV

™ Clear any messages previously issued.

■ This causes startV to begin the next search at the top of the text box.

value.

search to begin one character to the right of the last value found.

the search value, reset the variable.

USING CREATIVE TECHNIQUES

12

The String.lastIndexOf method searches a string for a specified value and returns the index position for the last occurrence of that value. You can use the lastIndexOf method to search a text box starting from the bottom, as shown in the following. Example: on (release) { if (text.lastIndexOf(searchV, startV ) != -1) { Selection.setFocus("text"); Selection.setSelection(text.lastIndexOf(search V, startV ),text.lastIndexOf(searchV, startV ) + length(searchV)); startV = text.lastIndexOf(searchV, startV ) - 1; messageV = ""; } else { startV = 0; startV = length(text); messageV = "Begining of text. Entry not found. Click button to start again."; } }

¢ Send a message to the

∞ Move to the test

§ Test your movie by first

user.

environment.

entering a name.

Note: See page 38 for instructions on how to test your movie.

¶ Click the Search button. ■ ActionScript searches for the value you entered.

251

FLASH ACTIONSCRIPT

CONVERT SYMBOLS uttons have several handlers that you can use to trigger actions. Movie clips also have handlers that you can use to trigger actions. However, there are times when you need to use both movie clip and button handlers. In such cases, you must convert a button to a movie clip or vice versa.

B

A handy technique for creating continuous play actions is to create a one-frame movie or movie clip with the onClipEvent(enterFrame) handler. When you use the onClipEvent(enterFrame) handler with a one-frame movie, the actions in the frame execute continuously, thereby creating a continuous action.

Creating a button that executes a continuous action is a good example of when you need to convert a button to a movie clip. If you want to create a button that executes a continuous action, such as rotating an object when the user clicks the object and continuing to rotate the object as long as the user holds down the mouse, you need to use the button on(press) and on(release) handlers and the movie clip onClipEvent(enterFrame) handler.

To use these actions in combination with one another, you must create the button that starts and stops the action, and then you must convert the button to a movie clip. You use the Symbol Properties dialog box to convert a button to a movie clip.

The on(press) handler triggers actions when the user clicks the object. The on(release) handler triggers actions when the user releases the mouse. You use on(press) to start a continuous action and on(release) to stop a continuous action.

Creating an object that users can click and drag is another common example of when you need to convert a button into a movie clip. For more information on creating a draggable object, see Chapter 2.

CONVERT SYMBOLS

Convert to Symbol...

⁄ Create a button.

¤ Add ActionScript.

Note: This example uses file chick.fla, which you can find on the CD-ROM that accompanies this book.

Note: See page 12 for information on creating a button.

252

F8

‹ Click Insert ➪ Convert to Symbol to open the Symbol Properties dialog box.

USING CREATIVE TECHNIQUES

12

After you convert a button to a movie clip, you must select the movie clip, click Edit ➪ Edit Symbols, and open the Actions panels to edit the script associated with the button. After editing the script, click Edit ➪ Edit Symbols to return to the main Timeline. You can also edit the script by double-clicking the movie clip and then opening the Actions panel.

› Type a symbol name.

Á Click OK.

ˇ Click Movie Clip.

■ The button is now a movie

‡ Select the movie clip.

° Add ActionScript.

clip.

253

FLASH ACTIONSCRIPT

CREATE ROTATION EFFECTS

I

t is obvious that you can use movie clip properties to create special effects. What may not be as obvious is how easy it is to create certain effects. For example, you can use the _rotation property to set the rotation value of an object. When you place an object on the Stage, it has a rotation value of 0. To rotate the object clockwise, increase the value. To rotate the object counterclockwise, decrease the value. You can create many interesting effects using the expression _rotation = _rotation + x, where x is equal to the speed at which you want the object to rotate. The higher the value of x, the faster the object will rotate. Negative x values rotate the object counterclockwise. Use _rotation = _rotation + x with onClipEvent(enterFrame) to create an object that rotates continually. Use it with mouse move to rotate the object when you move your mouse. Use it with mouse down to rotate the object when you click the mouse. In

fact, you should try it with each of the movie clip and button states. If you add some additional script to the _rotation = _rotation + x expression, you can create an object that rotates when you roll over it and stops rotating when you release the mouse. If you use the _rotation = _rotation + x expression along with the _x property or the _y property, you can rotate an object and move it at the same time. However, you will have to add some additional code to limit the area in which the object can move, or your object may move off the Stage. You can also use the expression _rotation = _xmouse to create an interesting effect. Keep in mind that a rotating object rotates around its registration point. You can change the registration point to change the rotation angle.

CREATE ROTATION EFFECTS

onClipEvent (enterFrame) {

Actions

Ctrl+Alt+A

⁄ Select the frame, button,

¤ Click Window ➪ Actions

or movie clip to which you want to add ActionScript.

to open the Actions panel.

Note: This example uses file rotate.fla, which you can find on the CD-ROM that accompanies this book.

254

‹ Select the event handler.

USING CREATIVE TECHNIQUES

12

To make a button rotate continuously, you can attach the script shown here to it. When you roll over the object, it rotates continuously until you roll out. Example: on (rollOver) { press = true; } on (rollOut) { press = false; }

Then convert the button to a movie clip and attach the script shown here to it. The variable text is the name of the text box. In this example, frogMC is the movie clip name. Example: onClipEvent (enterFrame) { if (press == true) { _root.frogMC._rotation =_root.frogMC._rotation + 10; } }

› Set the rotation.

ˇ Repeat steps 3 and 4 for

Á Move to the test

‡ Test your movie by

additional handlers.

environment.

clicking the mouse, moving the mouse, and rolling the cursor over the button to test the mouse handlers.

Note: See page 38 for instructions on how to test your movie.

255

FLASH ACTIONSCRIPT

CREATE A COLORING BOOK

U

sing the Color object, you can create an electronic coloring book. There are many different techniques that you can use. You can place color selections on the Stage; when the user clicks a color, ActionScript assigns the selection to a variable. When the user clicks an object, ActionScript applies the color. Alternatively, you can create a color slider and have the user create the color and then apply the color to objects. You can also code color changes into the object and have the object change color each time the user clicks the mouse. If you use the color selection method, start creating your coloring book by creating buttons to represent each possible color selection. Make the button the same color as the color that it represents. Store the hexadecimal color code to a variable when the user releases the mouse after clicking

the button. Use the parseInt function to tell ActionScript that the number you are assigning the variable is a hexadecimal number. For example, in newColor = parseInt( 0x00ccff); any value that starts with 0x is read by the parseInt function as a hexadecimal number. Assigning a color when the user clicks an object is tricky. The new Color method requires you to enter a target. In order for you to be able to assign a color when an object is clicked, the object must be a button. You cannot target buttons. You must create the button, add the script that makes the color change, convert the instance to a movie clip, and assign the movie clip the name that you specified when you created the button. For more information on converting a button to a movie clip, see the section “Convert Symbols.”

CREATE A COLORING BOOK

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file color.fla, which you can find on the CD-ROM that accompanies this book.

256

¤ Click

to open the Actions panel.

‹ Assign a color to a color variable. Note: This step initializes the color. ActionScript applies this color if the user does not select a color.

› Select the frame, button,

ˇ Assign the color of the

or movie clip to which you want to add ActionScript.

button to a variable.

USING CREATIVE TECHNIQUES

12

You can have each click of the mouse change the color of an object. Start by creating a color object and assigning it a color. Place the following script in frame 1. Frame 1 colorChanger = new Color( _root.circleMC ); colorChanger.setRGB(0xff0000);

Then create a button and assign the following script. Button on (release) { if (colorChanger.getRGB() == parseInt(0xff0000)) { colorChanger.setRGB(0x0000FF); } else if (colorChanger.getRGB() == parseInt(0x0000ff)) { colorChanger.setRGB(0xFFFF00); } else if (colorChanger.getRGB() == parseInt(0xffff00)) { colorChanger.setRGB(0x009900); } else if (colorChanger.getRGB() == parseInt(0x009900)) { colorChanger.setRGB(0xff0000); } }

Convert the button to a movie clip. Give the movie clip the name that you targeted in frame 1. In this example, the name is circleMC.

Á Select the frame, button,

· Use the variable that you

± Move to the test

or movie clip to which you want to add ActionScript.

created to assign a color to the Color object.

environment.

‡ Create a Color object.

‚ Convert the button to a

° Target a movie clip.

movie clip.

— Name the movie clip, using the name that you specified in step 8.

Note: See page 38 for instructions on how to test your movie.

¡ Test your movie by first

™ Click the object. ■ The script enables the user to click a color palette to set a color and then make an object that color.

clicking the color palette.

257

FLASH ACTIONSCRIPT

EMULATE PANELS

M

any programs use panels to provide users with options and tools that enable them to perform tasks. Panels appear on-screen at user request and are draggable, and the user can hide them from view when they are not needed. Emulating a panel using ActionScript is easy. You create an object that is draggable, visible when needed, invisible when not needed, and contains a set of options. The startDrag and stopDrag actions enable you to create objects that the user can drag. Both movie clips and buttons can be draggable. However, you want an object that is draggable when you click the mouse while the mouse is located over the object and for which the drag action stops when you release the mouse. Movie clips can be draggable when clicked, and you can stop the drag action when the

mouse is released, but the action is not limited to when the cursor is over the object. With buttons, you can start the drag action when the user clicks the object using the On Press handler. You can stop the drag action with the user releases the mouse or the pointer rolls out of the area of the object by using the Release and Roll Out handlers. Therefore, you start creating your panel by creating a draggable button that will act as a panel. Panels provide the user with options or tools that you develop. The options can be anything that you want. They can be buttons or movie clips that enable the user to perform an action. Create the options or tools and position them on the panel.

EMULATE PANELS

⁄ Create the button that will act as the panel. Note: This example uses file panel.fla, which you can find on the CD-ROM that accompanies this book.

258

¤ Click

to open the Actions panel.

› Create options and place

‹ Make the panel draggable.

Note: The options can be anything that you want.

Note: See page 56 for more information on making an object draggable.

them on the panel.

■ This example places a color bar on the panel.

USING CREATIVE TECHNIQUES

Panels are objects that you may want to use in many of your movies. The common library enables you to easily access objects that you use repeatedly, so you may want to place your panel in the common library. You may also want to turn your panel into a smart clip. Turning your panel into a smart clip enables you to use the same panel in many movies and enables you to adjust the features each time you use the panel.

12

When placing tools and options on a panel, make sure that your path names are correct. If you do not specify the correct paths, the panel will not function properly. There are a number of standard features that you may want to add to your panel. For example, you may want your panel to be resizable or reappear on the screen at a specified location.

Flash 5 ships with smart clips that enable you to create menus, radio buttons, and check boxes. You may find these useful when adding features to your panel. They are located in the common library.

ˇ Create a Close button. Note: See page 12 for information on creating a Close button.

‡ Set the movie clip

° Convert the panel button,

_visible property to false on release.

Close button, and options to a movie clip.

Note: See page 252 for more information on converting a button to a movie clip.

Á Select the button. CONTINUED

259

FLASH ACTIONSCRIPT

EMULATE PANELS (CONTINUED)

T

he user needs to be able to hide the panel from view when the user does not need the panel. You can use either the _visible property or the _alpha property to make an object invisible. However, when you use the _alpha property to make an object invisible, the object remains active. If the user clicks in the area in which the object is located, the object responds. If you use the _visible property, the object is inactive when it is not visible and does not respond when the user clicks in the area in which the object is located. When creating a panel, use the _visible property to hide the panel from view when the user does not need the panel. The object that you create to use as a panel is a draggable button. You need to change the _visible property of the object. Unfortunately, you cannot change the _visible property of a button. You can only change the properties of movies and movie clips. Therefore, you must convert the button and all the options to a movie clip. But first,

determine the instance name that you want to give the movie clip. Create a button that sets the _visible property of a movie clip to false when the user clicks the button. Use the movie clip name that you intend to give to the panel. Position the button on the panel. Group all the objects on the panel and convert everything to a movie clip. Then name the instance. You now have a draggable panel that the user can hide. Once hidden, the user needs to be able to return the object to the Stage when needed. You can create a button that returns the panel to the screen and place the button on the Stage. Or instead, if you use a Key method, you can add an action to the panel that returns the panel to the Stage when the user presses a key. Using a key instead of a button makes your panel self-contained and reusable. You can of course use both a key and a button.

EMULATE PANELS (CONTINUED)

· Name the movie clip

‚ Select the movie clip.

± Set the _visible

instance, using the name that you specified in step 7.

— Click

property to true when the user presses the Home key.

260

to open the Actions panel.

USING CREATIVE TECHNIQUES

12

You can use code similar to the code shown here to change the size of a panel. When the user presses Page Up, the script increases the size of the panel by 25 percent. When the user presses Page Down, the script decreases the size of the panel by 25 percent. When the user presses End, the script returns the panel to standard size. Example: onClipEvent (keyDown) { if (Key.isDown(Key.PGUP)) { setProperty (_root.panelMC, setProperty (_root.panelMC, } } onClipEvent (keyDown) { if (Key.isDown(Key.PGDN)) { setProperty (_root.panelMC, setProperty (_root.panelMC, } } onClipEvent (keyDown) { if (Key.isDown(Key.END)) { setProperty (_root.panelMC, setProperty (_root.panelMC, } }

_xscale, 125); _yscale, 125);

_xscale, 75); _yscale, 75);

_xscale, 100); _yscale, 100);

onClipEvent (enterFrame) {

Test Movie

Ctrl+Enter

¡ Click Control ➪ Test

™ Test your movie by first

¢ Press the Home key to

Movie to move to the test environment.

dragging the panel.

open the panel.

£ Click panel.

to close the

261

FLASH ACTIONSCRIPT

DEMYSTIFY TRIGONOMETRIC FUNCTIONS

Y

ou can use the Math object sin and cos methods to manipulate objects. These trigonometric functions find the sine or cosine of a value. You can use them with the _x and _y properties to move objects. Explaining trigonometry is beyond the scope of this book; however, the following is a formula that you can use to move objects located on the Stage: movieClip._x = l + Math.cos(s)*d movieClip._y = l + Math.sin(s)*a The l represents location, s speed, and a area. Use movieClip to specify the movie clip that you want to move. Use l to adjust the coordinate at which the movie clip is located. Use s to adjust the speed at which the object moves. The higher the value of s, the faster the object will move. Use a to adjust the area in which the object moves. The higher the value of a, the larger the area in which the object will move. In trigonometry, you use radians to measure the size of angles. You use the formula Math.PI/180 * degrees to convert degrees to radians. Although not essential, you may

find the formula Math.PI/180 * 2 a good base from which you can adjust the speed of your object. For the sake of the examples that follow, Math.PI/180 * 2 is assigned to the variable s, as shown in the following: s = Math.PI/180 * 2; You can move an object in a clockwise circle by setting each of the variables in both formulas to the same value. The following is an example: _sampleMC._x = 200 + Math.cos(s)*100; _sampleMC._y = 200 + Math.sin(s)*100; To cause the object to move in a counterclockwise direction, negate the speed value, as shown in the following: _sampleMC._x = 200 + Math.cos(-s)*100; _sampleMC._y = 200 + Math.sin(-s)*100;

MOVE AN OBJECT CLOCKWISE

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file trig_1.fla, which you can find on the CD-ROM that accompanies this book.

¤ Name a movie clip instance.

262

‹ Click

to open the Actions panel.

Á Move to the test

› Use the enterFrame

Note: See page 38 for instructions on how to test your movie.

handler.

ˇ Move the object clockwise.

environment.

‡ Test your movie. ■ The movie clip moves in a clockwise direction.

USING CREATIVE TECHNIQUES

12

You can add the scripts shown here to movie clips to create a simple but interesting design. Example:

redMC onClipEvent (enterFrame) { radianV += Math.PI/180*2; _root.redMC._y = 200 + Math.sin(radianV* 5)*50; _root.redMC._x = 200 + Math.cos(radianV* 1)*200; }

Example:

yellowMC onClipEvent (enterFrame) { radianV += Math.PI/180*2; _root.yellowMC._y = 200 + Math.sin(radianV* 5)* 50; _root.yellowMC._x = 200 + Math.cos(radianV* 2)* 200; }

MOVE AN OBJECT BACK AND FORTH

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file trig_2.fla, which you can find on the CD-ROM that accompanies this book.

¤ Name a movie clip instance.

‹ Click

to open the Actions panel.

Á Move to the test

› Use the enterFrame

Note: See page 38 for instructions on how to test your movie.

handler.

environment.

‡ Test your movie. ■ The movie clip moves back and forth.

ˇ Move the object back and forth. CONTINUED

263

FLASH ACTIONSCRIPT

DEMYSTIFY TRIGONOMETRIC FUNCTIONS (CONTINUED)

T

To increase the speed, multiply s by the factor by which you want to increase the speed. To decrease the speed, divide s by the factor by which you want to decrease the speed:

_sampleMC._x = 200 + Math.cos(s)*100;

_sampleMC._y = 200 + Math.sin(s *10)*100;

To move the object up and down, use the formula for the _y coordinate, but do not use the formula for the _x coordinate — for example:

To cause the object to move across the stage in a wave-like motion, increase the area value of _x and the speed of _y:

o move the object back and forth, use the formula for the _x coordinate but do not use the formula for the _y coordinate, as shown in the following:

_sampleMC._y = 200 + Math.sin(s)*100;

sampleMC._x = 200 + Math.cos(s)*300; sampleMC._y = 200 + Math.sin(s*10)*100;

To have the object move diagonally, use the same trigonometric function for both the _x and the _y coordinates, as shown here:

To cause the object to move up and down the Stage in a wave-like motion, increase the area value of _y and the speed of _x, as shown in the following:

_sampleMC._x = 200 + Math.cos(s)*100; _sampleMC._y = 200 + Math.cos(s)*100;

sampleMC._x = 200 + Math.cos(s * 10)*100; sampleMC._y = 200 + Math.sin(s)*300;

MOVE AN OBJECT DIAGONALLY

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file trig_3.fla, which you can find on the CD-ROM that accompanies this book.

¤ Name a movie clip instance.

264

‹ Click

to open the Actions panel.

Á Move to the test

› Use the enterFrame

Note: See page 38 for instructions on how to test your movie.

handler.

ˇ Move the object diagonally.

environment.

‡ Test your movie. ■ The movie clip moves diagonally.

USING CREATIVE TECHNIQUES

12

These scripts produce a very simple design. Example:

redMC onClipEvent (enterFrame) { radianV += Math.PI/180*2; _root.redMC._x = 200 + Math.cos(radianV)*100; }

Example:

yellowMC onClipEvent (enterFrame) { radianV += Math.PI/180*2; _root.yellowMC._y = 200 + Math.sin(radianV)* 100; _root.yellowMC._x = 200 + Math.cos(radianV)* 100; }

MOVE AN OBJECT IN A WAVE-LIKE MOTION

⁄ Select the frame, button, or movie clip to which you want to add ActionScript. Note: This example uses file trig_4.fla, which you can find on the CD-ROM that accompanies this book.

¤ Name a movie clip instance.

‹ Click

to open the Actions panel.

Á Move to the test

› Use the enterFrame

Note: See page 38 for instructions on how to test your movie.

handler.

environment.

‡ Test your movie. ■ The movie clip moves in a wave-like motion.

ˇ Move the object in a wave-like motion.

265

FLASH ACTIONSCRIPT

CREATE TRIGONOMETRIC SPECIAL EFFECTS

Y

ou can use the Math object sin or cos methods with the _xscale, _yscale, _height, _width, _rotation, and _alpha properties to create special effects. The _height and _width properties change the height and width of a movie clip using pixels. The _xscale and _yscale properties change the height and width of a movie clip using a percentage. Because these two methods change the size of a movie clip using two different methods, they produce slightly different results. The _xscale property can produce the illusion of an object flipping from left to right. The _yscale property can produce the illusion of an object flipping up and down. The _height and _width properties shrink and grow an object. The _rotation property produces a spinning effect. The object spins in one direction and then spins in the opposite direction. The _alpha property fades color in and out.

movieClip._property = Math.sin(s)*a movieClip._property = Math.cos(s)*a The s represents speed. The a represents area. Use movieClip to specify the name of the movie clip whose property you want to change. Use s to adjust the speed at which the property changes. The higher the value of s, the faster the property will change. Use a with the _height, _width, _xscale, and _yscale properties to determine the maximum size of the object. Remember, _height and _width use pixels, and _xscale and _yscale use a percentage. Use a with the rotation to adjust the number of rotations the object spins clockwise before spinning counterclockwise. You may use the formula Math.PI/180 * 2 as a base from which you adjust the speed of your object.

You can use the following formulas when using sin or cos with these properties: CREATE TRIGONOMETRIC SPECIAL EFFECTS

⁄ Select the frame, button, or movie clip to which you want to add ActionScript.

¤ Name the instance. Note: See page 10 for more information on naming an instance.

‹ Click

to open the Actions panel.

266

› Use the enterFrame handler.

ˇ Set the base speed.

USING CREATIVE TECHNIQUES

12

You attach the script that follows to three separate movie clips to create a design. It uses sin with the _height, _width, _rotation, and _alpha properties. Example: onClipEvent (enterFrame) { speedV += Math.PI/180 *2; _root.blockMC._height = Math.cos(speedV * 3 )* 100; _root.blockMC._width = Math.sin(speedV * 3 )* 100; _root.blockMC._rotation = Math.sin(speedV * 3 )* 100; _root.blockMC._alpha = Math.sin(speedV * 3 )* 100; }

Á Use sin to set the

° Move to the test

_xscale.

environment.

‡ Use sin to set the

Note: See page 38 for instructions on how to test your movie.

_rotation.

· Test your movie.

■ Your movie clip will scale and rotate.

267

FLASH ACTIONSCRIPT

USING THE DEBUGGER

C

orrecting errors — often referred to as debugging — is a normal part of writing a program. Flash provides several tools that can help you debug ActionScript. Use the Debugger to display a list of loaded movies, movie clips, properties, and variables. The Debugger enables you to view and adjust the properties and variables as the movie plays. Using the Debugger, you can experiment with values until you find the one that you need. You can then return to your script and make the necessary changes. The Debugger consists of a status bar, display list, Properties tab, Variables tab, and Watch list. The status bar displays the URL or path to a movie or movie clip. The display list displays all levels and instances that are currently loaded. As you add or remove movies and movie clips from the Stage, the display list automatically updates. A splitter bar enables you to open, close, or resize the display list.

The Properties tab displays all the properties associated with a movie clip. You can change a property value by double-clicking the property value and typing a new value. You cannot use an expression to change a value when using the Debugger. You must enter a string, Boolean, or number. When you change a property value, Flash reflects the change on the Stage immediately. You cannot change read-only values. The Variables tab displays all the variables and the current values of the variables. You can change the value of a variable by double-clicking the variable and typing a new value. Object and array values are displayed, but you cannot change them. If you have specific variables that you want to track, you can place them on the Watch list. The Watch list enables you to track a specified list of variables.

USING THE DEBUGGER

Debug Movie

Debugger

⁄ Click Window ➪

¤ Click Control ➪ Debug

Debugger to open the Debugger.

Movie to activate the Debugger.

268

Ctrl+Shift+Enter

DEBUGGING ACTIONSCRIPT

The Debugger uses a special version of Flash Player — the Flash Debug Player — that installs automatically when you install Flash 5. To activate the Flash Debug Player, click Control ➪ Debug Movie. You can use the Flash Debug Player as a standalone player. If you choose Debugging Permitted under the Flash tab of the Publish Settings dialog box, when you publish your Flash movie, you can use the Debugger as you play your movie. Just click Control ➪ Debugger in the Flash Debug Player menu. When using Debugger with the Flash Debug Player, Flash must be open. You may want to password-protect your movie because anyone viewing your movie using the Flash Debug Player will also be able to view your property and variable settings. The Flash tab of the Publish Settings dialog box provides an option that enables you to password-protect the Debugger option.

13

To add a variable to the Watch list, select the variable, click in the upper-right corner of the Debugger panel to open the menu, and then click Add Watch. To remove a variable from the Watch list, select the variable, click , and then click Remove Watch.

You can download the latest version of the Flash Debug Player from the Macromedia Web site. A link to the site is included on the CD-ROM that accompanies this book.

_level0

_alpha

_level0

100

"Olive and Emerald the Pogo Jumping Frogs"

‹ Click a level or instance to select it.

› Click the Properties tab to

Á Click the Variables tab to

view properties.

view the variables.

ˇ Double-click a value and

‡ Double-click a value and

type to change a property.

type to change a variable.

■ You can use Debugger to troubleshoot your movies.

269

FLASH ACTIONSCRIPT

USING THE OUTPUT WINDOW

T

he Output window is part of the test environment. The Output window displays information to help you troubleshoot your movie. If you have syntax errors in your movie, error messages automatically display in the Output window when you enter the test environment. Error messages help you locate problems with your script.

The Output window’s Options menu provides you with options that enable you to copy the contents of the Output window to the clipboard, clear the Output window, save the contents of the Output window to a file, or print the contents of the Output window. Choosing the Save to File option on the menu enables you to save the contents of the Output window as a TXT or LOG file. The Options menu also enables you to select how in-depth you want the error messages that you receive to be. Choose from None, Errors, Warnings, and Verbose. Choosing None turns off the display of error messages.

You can use the trace action to evaluate an expression. This is useful when you are debugging your movie and you need to know the value that an expression returns. The results of the trace action display in the Output window. The syntax for the trace action is trace(expression); Use the expression argument to specify the expression that you want to evaluate. For example, the following script increments the value of x each time the user clicks a button and sends the results to the Output window: on (release) { trace(++x); } You can also use the trace action to display messages to anyone who views your movie using the test environment. For example, trace("hello"); displays "hello" in the Output window.

USING THE OUTPUT WINDOW

Layer 1 Output

USING THE TRACE ACTION

⁄ Select the frame, button,

¤ Click

to open the Actions panel.

or movie clip to which you want to add ActionScript.

‹ Use the trace action to evaluate an expression.

Note: This example uses file trace.fla, which you can find on the CD-ROM that accompanies this book.

› Move to the test

270

environment.

ˇ Click Window ➪ Output to open the Output window.

DEBUGGING ACTIONSCRIPT

13

The script shown here uses the trace action to display changes made to an array. Script: on (release) { name = ["George”, "John", "James"]; trace (name); name[1] = "Chris"; trace (name); name.push("Gene", "Charles", "Sue" ); trace (name); }

Results of the First Trace: George,John,James

Results of the Second Trace: George,Chris,James

Results of the Third Trace: George,Chris,James,Gene,Charles,Sue

Options

Á Click the button to test your movie.

■ Each time you click the

button, the ouput window will display the results of the trace.

THE OPTIONS MENU

⁄ Click Options to open the Options menu.

¤ Select an option.

■ You can use the options

menu to copy the contents of the Output window to the clipboard, clear the Output window, save the contents of the Output window to a file, or print the contents of the output window.

271

FLASH ACTIONSCRIPT

USING LIST OBJECTS

I

n the test environment, you can use the menu choice Debug ➪ List Objects to display levels, object types, and target paths for the current frame in the Output window. Object types include shape, movie clip, text, and button. The information provided by the Debug ➪ List Object menu choice is useful when you want to find a target path or what text is assigned to a text field.

The following is an example of output from the Debug ➪ List Objects menu selection. Example: Level #0: Frame=1 Edit Text: Variable=_level0.titleV Text="" Movie Clip: Frame=1 Target="_level0.Olive” Shape: Movie Clip: Frame=1 Target="_level0.Emerald" Shape: Button: Shape: Shape: Edit Text: Variable= Text="Start Movie\r"

When you use Debug ➪ List Objects, the Output window does not update automatically as the Debugger does. You must make the menu choice each time you want to retrieve information.

USING LIST OBJECTS

List Objects

Ctrl+L

Actions Test Movie

⁄ Create your movie.

272

Ctrl+Enter

¤ Click Control ➪ Test

‹ Click Debug ➪ List

Movie to move to the test environment.

Objects.

■ The results display in the Output window.

DEBUGGING ACTIONSCRIPT

13

USING LIST VARIABLES

I

n the test environment, you can use the menu choice Debug ➪ List Variables to display all the movie variables in the Output window. The information provided by the Debug ➪ List Variables menu choice is useful when you want to find a variable name or the value assigned to a variable. All the values assigned to an array are displayed in the Output window.

The following is an example of output from the Debug ➪ Lists Variables menu selection. namesA is an array. Example: Level #0: Variable _level0.$version = "WIN 5,0,30,0" Variable _level0.namesA = [object #1] [ 0:"Emerald", 1:"Jade" ] Variable _level0.nameV = "Emerald the Pogo Jumping Frog"

When you use Debug ➪ List Variables, the Output window does not update automatically as the Debugger does. You must make the menu choice each time that you want to retrieve information.

USING LIST VARIABLES

List Variables

Ctrl+Alt+V

Actions Test Movie

⁄ Create your movie.

Ctrl+Enter

¤ Click Control ➪ Test

‹ Click Debug ➪ List

Movie to move to the test environment.

Variables.

■ The results display in the Output window.

273

FLASH ACTIONSCRIPT

DEBUG YOUR SCRIPT here are techniques that you can use to effectively create and debug ActionScript. For starters, you should build your movie in a modular fashion, testing each section as you develop it. This enables you to identify problems as they arise.

T

you do not work with other developers, comments are important. You may need to revise your code weeks, months, or years later. It is very easy to forget the logic that you used to develop your code. Use comments to explain what you are doing and why you are doing it.

As you create your scripts, you should save often, giving each save a different version number. If your script gets extremely complex and stops working, this enables you to go back to the last working version of the script.

Give the variables, arrays, functions, and objects that you create meaningful names. This will make it easier for you and others who view your code to understand your code.

If a portion of script does not work, try breaking the script down into component parts. This enables you to narrow things down so that you can determine which portion of the script is not working. You can also comment out portions of the script and test it. Again, this helps narrow down where the error is located. Use comments to document your code. This is very important if you are working with other developers. Even if

Develop a naming convention and stick with it. For example, you can type the first word in a variable name in small letters, and subsequent words can start with capital letters. The variable name playerFirstName is an example of this convention. When trying to understand a movie written by someone else, use Movie Explorer to find and view ActionScript.

DEBUG YOUR SCRIPT

Colored Syntax

⁄ Add comments.

274

¤ Add meaningful names. ‹ Add a naming convention.

› Click ➪ Colored Syntax to use colored syntax.

ˇ Click ➪ Check Syntax to perform a syntax check.

DEBUGGING ACTIONSCRIPT

13

When using the Action panel, use Colored Syntax.

COMMON ERRORS

Perform syntax checks. This is particularly important if you are working in the Expert Mode.

ERROR

SOLUTION

Misspelled variable or array name

Make sure that you spell variable and array names the same each time that you use them.

Expression box not checked

If you are working in Normal Mode, make sure that you check the Expression box when you enter an expression.

Using = to perform a comparison

The operator = is the assignment operator. If you want to perform a comparison, such as if name == "George", use ==, the equality operator.

Give every variable, function, object, and array a unique name.

Movie Explorer

Ctrl+Alt+M

Á Click Window ➪ Movie

‡ Click

Explorer to open Movie Explorer.

hierarchy.

° Click hierarchy.

to contract the to expand the

· View the ActionScript. ■ You can develop your

scripts in a way that makes it easy for you to debug them.

275

FLASH ACTIONSCRIPT

KEY CODE VALUES

T

he tables that follow list all of the keys on a standard keyboard and the corresponding key code values.

LETTERS A TO Z AND NUMBERS 0 TO 9

LETTER OR NUMBER

KEY CODE

LETTER OR NUMBER

KEY CODE

LETTER OR NUMBER

KEY CODE

LETTER OR NUMBER

KEY CODE

A

65

J

74

S

83

1

49

B

66

K

75

T

84

2

50

C

67

L

76

U

85

3

51

D

68

M

77

V

86

4

52

E

69

N

78

W

87

5

53

F

70

O

79

X

88

6

54

G

71

P

80

Y

89

7

55

H

72

Q

81

Z

90

8

56

I

73

R

82

0

48

9

57

KEYS ON THE NUMERIC KEYPAD

276

KEY

KEYCODE

KEY

KEYCODE

KEY

KEYCODE

Number Pad 0

96

Number Pad 6

102

Add

107

Number Pad 1

97

Number Pad 7

103

Enter

108

Number Pad 2

98

Number Pad 8

104

Subtract

109

Number Pad 3

99

Number Pad 9

105

Decimal

110

Number Pad 4

100

Multiply

106

Divide

111

Number Pad 5

101

FLASH ACTIONSCRIPT QUICK REFERENCE

14

FUNCTION KEYS

KEY

KEYCODE

KEY

KEYCODE

KEY

KEYCODE

F1

112

F5

116

F9

120

F2

113

F6

117

F10

121

F3

114

F7

118

F11

122

F4

115

F8

119

F12

123

OTHER KEYS

KEY

KEYCODE

KEY

KEYCODE

KEY

Backspace

8

Esc

27

Tab

9

Spacebar

Clear

12

Page Up

Enter

13

Page Down

Shift

16

Control

17

Alt Cap Lock

KEYCODE

KEY

KEYCODE

Right Arrow 39

-_

189

32

Down Arrow 40

/?

191

33

Insert

45

`~

192

34

Delete

46

[{

219

End

35

Help

47

\|

220

Home

36

Num Lock

144

]}

221

18

Left Arrow

37

;:

186

‘’’

222

20

Up Arrow

38

=+

187

277

FLASH ACTIONSCRIPT

URL ENCODING CHARACTERS

T

he loadVariables action reads data from an external file. You cannot read certain characters directly. You must use URL encoding for these characters. For example, if your text file includes temperature=+15, ActionScript will read it as

278

temperature=15, dropping the plus. The URL code for the + is %2b. To have ActionScript read the entry correctly, enter this: temperature=%2b15. The following is a complete list of URL codes.

URL CHARACTER CODE

URL CHARACTER CODE

URL CHARACTER CODE

URL CHARACTER CODE

backspace

%08

3

%33

J

%4A

a

%61

tab

%09

4

%34

K

%4B

b

%62

linefeed

%0A

5

%35

L

%4C

c

%63

return

%0D

6

%36

M

%4D

d

%64

space

%20

7

%37

N

%4E

e

%65

!

%21

8

%38

O

%4F

f

%66

"

%22

9

%39

P

%50

g

%67

#

%23

:

%3A

Q

%51

h

%68

$

%24

;

%3B

R

%52

i

%69

%

%25




%3E

U

%55

l

%6C

(

%28

?

%3F

V

%56

m

%6D

)

%29

@

%40

W

%57

n

%6E

*

%2A

A

%41

X

%58

o

%6F

+

%2B

B

%42

Y

%59

p

%70

,

%2C

C

%43

Z

%5A

q

%71

-

%2D

D

%44

[

%5B

r

%72

.

%2E

E

%45

\

%5C

s

%73

/

%2F

F

%46

]

%5D

t

%74

0

%30

G

%47

^

%5E

u

%75

1

%31

H

%48

_

%5F

v

%76

2

%32

I

%49

`

%60

w

%77

FLASH ACTIONSCRIPT QUICK REFERENCE

14

URL CHARACTER CODE

URL CHARACTER CODE

URL CHARACTER CODE

URL CHARACTER CODE

x

%78

¿

%BF

Ö

%D6

î

%EE

y

%79

À

%C0

Ø

%D8

ï

%EF

z

%7A

Á

%C1

Ù

%D9

_

%F0

{

%7B

Â

%C2

Ú

%DA

ñ

%F1

|

%7C

Ã

%C3

Û

%DB

ò

%F2

}

%7D

Ä

%C4

Ü

%DC

ó

%F3

~

%7E

Å

%C5

_

%DD

ô

%F4

¢

%A2

Æ

%C6

_

%DE

õ

%F5

£

%A3

Ç

%C7

ß

%DF

ö

%F6

¥

%A5

È

%C8

à

%E0

÷

%F7

|

%A6

É

%C9

á

%E1

ø

%F8

§

%A7

Ê

%CA

â

%E2

ù

%F9

«

%AB

Ë

%CB

ã

%E3

ú

%FA

¬

%AC

Ì

%CC

ä

%E4

û

%FB

¯

%AD

Í

%CD

å

%E5

ü

%FC

º

%B0

Î

%CE

æ

%E6

_

%FD

±

%B1

Ï

%CF

ç

%E7

_

%FE

ª

%B2

_

%D0

è

%E8

ÿ

%FF

,

%B4

Ñ

%D1

é

%E9

µ

%B5

Ò

%D2

ê

%EA

»

%BB

Ó

%D3

ë

%EB

1/4

%BC

Ô

%D4

ì

%EC

1/2

%BD

Õ

%D5

í

%ED

LIST OF KEYWORDS Keywords are words that ActionScript reserves for specific use within the language. You cannot use keywords to name variables, functions, or labels. The following is a list of ActionScript keywords.

break

continue

delete

else

for

function

if

in

new

return

this

typeof

var

void

while

with

279

FLASH ACTIONSCRIPT

ACTIONS APPENDED WITH NUM

W

hen you use loadMovie, unLoadMovie, loadVariables, print, or printAsBitmap in Normal Mode, ActionScript may substitute those actions with loadMovieNum, unLoadMovieNum, loadVariablesNum, printNum, or printAsBitmapNum. In Normal Mode, when using the loadMovie, unLoadMovie, loadVariables, print, or printAsBitmap actions you use the location parameter to specify either a level number or target path. A level number is an integer. A target path is a string. Flash Player needs to know if the location is a string or a number. Therefore, ActionScript uses two versions of the actions: the action name and the action name appended with Num. ActionScript uses the action name with strings and the action name appended with Num with numbers. When in Normal Mode, if you select Target in the Location field, ActionScript uses the action name. If you select a Level in the Location field, ActionScript uses the action name appended with Num. ActionScript makes the selection

automatically. In fact, Normal Mode does not list action names appended with Num in the Toolbox list. In the Expert mode, the programmer must decide whether to use the action name or the action name appended with Num. The Toolbox list lists them both. The programmer should use the action if specifying a target path and the action appended with Num if specifying a level using an integer. Examples:

loadVariableNum ("http://www. entercompanyhere.com/anymovie.swf", 3) loadVariable ("http://www.entercompanyhere. com /anymovie.swf", "_root.targetClip") Note: If you specify the level using a string, use loadVariable. loadVariable ("http://www.entercompanyhere. com/anymovie.swf", "_level1")

HEXADECIMAL COLOR CODES

Y

ou can specify color using the red, green, and blue hexadecimal values shown in the following table. This table is not a complete list of hexadecimal values.

COLOR

280

RED

GREEN BLUE

COLOR

RED

GREEN BLUE

aliceblue

F0

F8

FF

brown

A5

2A

2A

antiquewhite

FA

EB

D7

burlywood

DE

B8

87

aqua

00

FF

FF

cadetblue

5F

9E

A0

aquamarine

7F

FF

D4

chartreuse

7F

FF

00

azure

F0

FF

FF

chocolate

D2

69

1E

beige

F5

F5

DC

coral

FF

7F

50

bisque

FF

E4

C4

cornflowerblue

64

95

ED

black

00

00

00

cornsilk

FF

F8

DC

blanchedalmond

FF

EB

CD

crimson

DC

14

3C

blue

00

00

FF

cyan

00

FF

FF

blueviolet

8A

2B

E2

darkblue

00

00

8B

FLASH ACTIONSCRIPT QUICK REFERENCE

COLOR

RED

GREEN BLUE

COLOR

RED

GREEN BLUE

darkcyan

00

8B

8B

indigo

4B

00

82

darkgoldenrod

B8

86

0B

ivory

FF

FF

F0

darkgray

A9

A9

A9

khaki

F0

E6

8C

darkgreen

00

64

00

lavender

E6

E6

FA

darkkhaki

BD

B7

6B

lavenderblush

FF

F0

F5

darkmagenta

8B

00

8B

lawngreen

7C

FC

00

darkolivegreen

55

6B

2F

lemonchiffon

FF

FA

CD

darkorange

FF

8C

00

lightblue

AD

D8

E6

darkorchid

99

32

CC

lightcoral

F0

80

80

darkred

8B

00

00

lightcyan

E0

FF

FF

darksalmon

E9

96

7A

lightgoldenrodyellow

FA

FA

D2

darkseagreen

8F

BC

8F

lightgreen

90

EE

90

darkslateblue

48

3D

8B

lightgray

D3

D3

D3

darkslategray

2F

4F

4F

lightpink

FF

B6

C1

darkturquoise

00

CE

D1

lightsalmon

FF

A0

7A

darkviolet

94

00

D3

lightseagreen

20

B2

AA

deeppink

FF

14

93

lightskyblue

87

CE

FA

deepskyblue

00

BF

FF

lightslategray

77

88

99

dimgray

69

69

69

lightsteelblue

B0

C4

DE

dodgerblue

1E

90

FF

lightyellow

FF

FF

E0

firebrick

B2

22

22

lime

00

FF

00

floralwhite

FF

FA

F0

limegreen

32

CD

32

forestgreen

22

8B

22

linen

FA

F0

E6

fuchsia

FF

00

FF

magenta

FF

00

FF

gainsboro

DC

DC

DC

maroon

80

00

00

ghostwhite

F8

F8

FF

mediumaquamarine

66

CD

AA

gold

FF

D7

00

mediumblue

00

00

CD

goldenrod

DA

A5

20

mediumorchid

BA

55

D3

gray

80

80

80

mediumpurple

93

70

DB

green

00

80

00

mediumseagreen

3C

B3

71

greenyellow

AD

FF

2F

mediumslateblue

7B

68

EE

honeydew

F0

FF

F0

mediumspringgreen

00

FA

9A

hotpink

FF

69

B4

mediumturquoise

48

D1

CC

indianred

CD

5C

5C

14

Continued

281

FLASH ACTIONSCRIPT

HEXADECIMAL COLOR CODES (CONTINUED)

282

COLOR

RED

GREEN BLUE

COLOR

RED

GREEN BLUE

mediumvioletred

C7

15

85

royalblue

41

69

E1

midnightblue

19

19

70

saddlebrown

8B

45

13

mintcream

F5

FF

FA

salmon

FA

80

72

mistyrose

FF

E4

E1

sandybrown

F4

A4

60

moccasin

FF

E4

B5

seagreen

2E

8B

57

navajowhite

FF

DE

AD

seashell

FF

F5

EE

navy

00

00

80

sienna

A0

52

2D

oldlace

FD

F5

E6

silver

C0

C0

C0

olive

80

80

00

skyblue

87

CE

EB

olivedrab

6B

8E

23

slateblue

6A

5A

CD

orange

FF

A5

00

slategray

70

80

90

orangered

FF

45

00

snow

FF

FA

FA

orchid

DA

70

D6

springgreen

00

FF

7F

palegoldenrod

EE

E8

AA

steelblue

46

82

B4

palegreen

98

FB

98

tan

D2

B4

8C

paleturquoise

AF

EE

EE

teal

00

80

80

palevioletred

DB

70

93

thistle

D8

BF

D8

papayawhip

FF

EF

D5

tomato

FF

63

47

peachpuff

FF

DA

B9

turquoise

40

E0

D0

peru

CD

85

3F

violet

EE

82

EE

pink

FF

C0

CB

wheat

F5

DE

B3

plum

DD

A0

DD

white

FF

FF

FF

powderblue

B0

E0

E6

whitesmoke

F5

F5

F5

purple

80

00

80

yellow

FF

FF

00

red

FF

00

00

yellowgreen

9A

CD

32

rosybrown

BC

8F

8F

FLASH ACTIONSCRIPT QUICK REFERENCE

14

BUTTON HANDLERS

Y

ou use button handlers to instruct Flash on how to respond when the user clicks, moves the mouse over, or interacts in some other way with a button. The table that follows lists button handlers and their purpose.

HANDLER

PURPOSE

on(release)

Performs specified actions when the pointer is over the button and the user releases the mouse. This is the default handler.

on(press)

Performs specified actions when the pointer is over the button and the user presses the mouse.

on(releaseOutside)

Performs specified actions when the user drags the pointer outside the button area and releases the mouse.

on(rollOver)

Performs specified actions when the user rolls the pointer over the button.

on(rollOut)

Performs specified actions when the user rolls the pointer over and then outside of the button area.

on(dragOver)

Performs specified actions when the user clicks the button, drags the pointer away from the button, and then drags the pointer back over the button.

on(dragOut)

Performs specified actions when the pointer is over the button and the user presses the mouse and then drags the pointer outside the button area.

on(keyPress, "key")

Performs specified actions when the user presses a specified key.

MOVIE CLIP HANDLERS

Y

ou use movie clip handlers to instruct Flash on how to respond when the user loads or unloads a movie clip, enters a frame, moves the mouse, presses a key, or interacts in some other way with a movie clip. The table that follows lists movie clip handlers and their function.

HANDLER

PURPOSE

onClipEvent(load)

Performs the specified actions when the movie clip appears on the Timeline. This is the default handler.

onClipEvent(unload)

Performs the specified actions in the first frame after you remove the movie clip from the Timeline.

onClipEvent(enterFrame) Performs the specified actions as a frame plays. onClipEvent(mouseMove) Performs the specified actions every time the user moves the mouse. onClipEvent(mouseDown) Performs the specified actions when the user presses the mouse. onClipEvent(mouseUp)

Performs the specified actions when the user releases the mouse.

onClipEvent(keyDown)

Performs the specified actions when the user presses any key.

onClipEvent(keyUp)

Performs the specified actions when the user releases any key.

onClipEvent(data)

Performs the specified actions when ActionScript receives data.

283

FLASH ACTIONSCRIPT

OPERATORS

Y

ou use operators to combine, compare, or modify values. The table that follows lists operators and their purpose.

OPERATOR NAME

284

PURPOSE

!

Logical Not

Converts an expression that returns true to false and an expression that returns false to true.

!=

Inequality

Used to compare to values. Returns true if two values are not equal. Returns false if two values are equal.

""

Quotes

Used to enclose strings.

%

Modulo

Returns the remainder of one expression divided by another expression.

&&

Short-Circuit AND

Evaluates two expressions. Returns true if expression 1 and expression 2 return true.

()

Parenthesis

Groups expressions to control precedence. Encloses arguments.

*

Multiplication

Multiplies expression1 by expression 2.

+

Addition

Adds expression 1 to expression 2.

++

Increment

Adds 1 to a value and returns the original value.

-

Minus

Negates a number or substracts expression 2 from expression 1.

--

Decrement

Substract 1 from a value and returns the original value.

/

Division

Divides expression 1 by expression 2.


=

Greater than or equal to

Compares two expressions. Returns true if expression 1 is greater than or equal to expression 2. Returns false if expression 1 is not greater than or equal to expression 2.

and

Evaluates two expressions. Returns true if expression 1 and expression 2 return true. Deprecated in Flash 5.

not

Converts an expression that returns true to false and an expression that returns false to true. Deprecated in Flash 5.

or

Compares two expressions. Returns true if expression 1 returns true or expression 2 returns true. Deprecated in Flash 5.

FLASH ACTIONSCRIPT QUICK REFERENCE

OPERATOR NAME

PURPOSE

typeof

Returns whether an expression is a movie clip, object, or function.

void

Returns a null value for an expression.

||

OR

14

Compares two expressions. Returns true if expression 1 returns true or expression 2 returns true.

FUNCTIONS

A

function is a block of script that can be reused. The table that follows lists functions and their purpose.

FUNCTION

PURPOSE

FUNCTION

PURPOSE

Boolean

Converts a variable, number, or string to a Boolean.

newline

Inserts a blank line in ActionScript code.

escape

Converts an expression to URL-encoded format.

Number

Converts a string or Boolean to a number.

eval

Returns the value of a variable, property, value, or the reference to an object or movie clip.

parseFloat

Converts a string to a floating point number.

The Boolean value false.

parseInt

Converts a string to an integer.

false

random

Returns a random number.

scroll

Returns the line number of the top line in a text box.

String

Converts a number, Boolean, variable, or object to a string.

targetPath

Returns the target path of a MovieClip object.

true

The Booloean value true.

unescape

Converts an expression in URLencoded format to ASCII format.

getProperty Retrieves properties. getTimer

Retrieves the number of milliseconds that have elapsed.

getVersion

Retrieves the version of Flash Player on the local computer.

int

Rounds a number to an integer.

isFinite

Returns true if a value is equal to infinity. Returns false if it is not.

isNaN

Returns true if an expression is not a number.

maxscroll

Finds the highest value allowed for the scroll property.

updateAfterEvent Updates the display after the clip event.

285

FLASH ACTIONSCRIPT

ACTIONS

Y

ou use actions to send commands in ActionsScript. You can use actions to start or stop a movie, load or

unload a movie, or perform myriad other tasks. The following table lists the actions available to you in ActionScript.

ACTION

PURPOSE

ACTION

PURPOSE

break

Used with the for, for...in, do while, and while actions. The break action instructs ActionSript to break out of a loop.

loadMovie

Load and displays several movies at once or switches movies without closing Flash Player.

loadVariables

Loads variables from an external file.

onClipEvent

Enables you to select a movie clip handler.

play

Plays a movie.

Used with while and do...while loops. With while loops, causes ActionScript to return to the top of the loop. With do...while loops, causes ActionScript to go to the bottom of the loop.

print

Prints a movie.

removeMovieClip

Removes a movie clip from the Stage.

return

Specifies the value returned by a function.

delete

Deletes an object or variable.

set variable

duplicateMovieClip

Copies of a movie clip instance.

Enables you to assign a value to a variable.

else

Used with if statements. Executes statements if all other conditions are not met.

setProperty

Enables you to set the property of a movie clip.

startDrag

Makes an object draggable.

stop

Stops a movie from playing.

stopAllSounds

Stop all sounds that are currently playing.

comment

continue

286

Enables you to add text to your script. Comments have no effect on your script. Use comments to document your script.

evaluate

Creates a blank line with a semi-colon.

for

Used to execute a statement or series of statements repeatedly.

stopDrag

Stops a drag action.

for...in

Loops through object properties or elements in an array.

tellTarget

Sends statements to a Timeline.

FSCommand

Sends commands to Flash Player.

trace

function

Defines custom functions.

Displays messages in the Output window.

getUrl

Opens a Web page.

unloadMovie

Unloads a movie.

goto

Stops or plays a movie.

if

Evaluates a condition. If the condition is true, executes statements.

ifFrameLoaded

Checks the status of a movie download.

include

Includes script written with a text editor in your Flash movie.

toggleHighQuality Toggles antialiasing on and off.

var

Declares a local variable.

while

Runs a statement or series of statements repeatedly.

with

Enables you to execute a statement or series of statements on an object or movie clip.

FLASH ACTIONSCRIPT QUICK REFERENCE

14

PROPERTIES

T

his table lists movie clip properties. You can use the setProperty action to set many of these properties. You can use the getProperty function to retrieve the

value of these properties. However, if a property is readonly, you can retrieve but not set the property. Read-only properties are marked with an asterisk.

PROPERTY

PURPOSE

PROPERTY

PURPOSE

_alpha

Returns a value between 0 and 100. A transparent movie clip has a value of 0. An opaque movie clip has a value of 100.

_totalframes*

Returns the total number of frames in a movie clip.

_url*

Returns the URL from which the movie clip was downloaded.

_visible

Returns the visibility status. Returns true if the movie clip is visible. Returns false if the movie clip is not visible.

_width

Returns the width of the movie clip.

_x

Returns the x coordinate of a movie clip, using global coordinates.

_xmouse*

Returns the x coordinate of the mouse position.

_xscale

Returns the amount of horizontal scaling that the script or the user has applied to a movie clip.

_y

Returns the y coordinate of a movie clip, using global coordinates.

_ymouse*

Returns the y coordinate of the mouse position.

_yscale

Returns the amount of vertical scaling that the script or the user has applied to a movie clip.

_currentframe*

Returns the frame in which the playhead is located.

_droptarget*

Returns the absolute path of the movie clip on which the user dropped a draggable instance.

_focusrect

Returns true if a yellow rectangle will appear around the button or text box that has focus when the user presses the tab key. Otherwise, it returns false.

_framesloaded*

Returns the number of frames loaded.

_height

Returns the height of a movie clip in pixels.

_highquality

Returns the movie clip quality.

_name

Returns the name of a movie clip.

_quality

Returns the movie clip quality.

_rotation

Returns the rotation value.

_soundbuftime

Returns the number of seconds of streaming sound buffered before the movie starts to stream.

_target*

Returns the target path of a movie clip instance.

287

FLASH ACTIONSCRIPT

OBJECTS ARRAY OBJECT

You can use an array to group related data. The table that follows lists the methods you can use with the Array object. METHOD

PURPOSE

METHOD

PURPOSE

concat

Concatenates and returns an array.

slice

Extracts elements from an array.

join

Joins elements in an array to form a string.

sort

Sorts an array.

pop

Removes the last element from an array.

splice

Adds or removes elements from an array.

push

Adds elements to the end of an array.

toString

Converts an array to a string.

reverse

Reverses an array.

unshift

Adds elements to the beginning of the array.

shift

Removes the first element from an array.

length

Returns the length of an array.

BOOLEAN OBJECT

You can use the Boolean object to find the string value of a Boolean or to return the primitive value of the Boolean object. The following table lists the methods of the Boolean object.

METHOD

PURPOSE

toString Returns the string value of a Boolean object. valueOf

Returns the primitive value of a Boolean object.

COLOR OBJECT

You can use the Color object methods to retrieve and set the color values. The table that follows lists the methods of the Color object and their purpose.

METHOD

PURPOSE

getRGB

Returns the value of the last setRGB call.

getTransform Returns the value of the last setTansform call. setRGB

Sets the hexadecimal value for a Color object.

setTransform Sets the color transform for a Color object.

288

FLASH ACTIONSCRIPT QUICK REFERENCE

14

DATE OBJECT

You can use the Date object to retrieve and set the date. The table that follows lists the methods and purposes of the Date object. METHOD

PURPOSE

METHOD

PURPOSE

getDate

Returns the day of the month in local time.

getUTCSeconds

Returns the second in universal time.

getDay

Returns the day of the week in local time.

getYear

Returns the year in local time.

setDate

Sets the day of the month in local time.

setFullYear

Sets the year in local time.

setHours

Sets the hour in local time.

setMilliseconds

Sets the millisecond in local time.

setMinutes

Sets the minute in local time.

setMonth

Sets the month in local time.

setSeconds

Sets the second in local time.

setTime

Sets the time in milliseconds.

setUTCDate

Sets the date in universal time.

getFullYear

Returns the four-digit year in local time.

getHours

Returns the hour in local time.

getMilliseconds

Returns the millisecond in local time.

getMinutes

Returns the minute in local time.

getMonth

Returns the month in local time.

getSeconds

Returns the second in local time.

getTimer

Returns the number of milliseconds since midnight January 1, 1970 universal time.

setUTCFullYear

Sets the year in universal time.

local time and universal time.

setUTCHours

Sets the hour in universal time.

getUTCDate

Returns the day of the month in universal time.

setUTCMilliseconds

Sets the milliseconds in universal time.

getUTCDay

Returns the day of the week in universal time.

setUTCMinutes

Sets the minute in universal time.

getUTCFullYear

Returns the four-digit year in universal time.

setUTCMonth

Sets the month in universal time.

getUTCHours

Returns the hour in universal time.

setUTCSeconds

Sets the second in universal time.

getTimezoneOffset Returns the difference between

getUTCMilliseconds Returns the millisecond in universal time.

getUTCMinutes

Returns the minute in universal time.

getUTCMonth

Returns the month in universal time.

setYear

Sets the year in local time.

toString

Returns the date and time as a string.

Date.UTC

Returns the number of milliseconds between midnight January 1, 1970, universal time, and a specified time.

289

FLASH ACTIONSCRIPT

KEY OBJECT

You can use the methods of the Key object to enable users to manipulate objects with keys or to respond to key presses. The following table lists the methods of the Key object and their purpose.

METHOD

PURPOSE

getAscii

Returns the ASCII code for the last key pressed.

getCode

Returns the virtual key code for the last key pressed.

isDown

Returns true if a specified key is pressed.

isToggled Returns true if Num Lock or Caps Lock are on.

MATH OBJECT

You can use the methods of the Math object to manipulate numbers and perform mathematical

290

calculations. The following table lists the methods of the Math object and their purpose.

METHOD

PURPOSE

METHOD

PURPOSE

abs

Returns the absolute value of a value.

max

acos

Returns the arc cosine of a value.

Compares two numbers and returns the larger.

asin

Returns the arc sine of a value.

min

atan

Returns the arc tangent of a value.

Compares two numbers and returns the smaller.

Computes the angle from the x-axis to the point.

pow

Raises a number to a power.

atan2

random

Returns a random number. Rounds a number.

ceil

Rounds a number up.

round

cos

Returns the cosine of a value.

sin

Returns the sine of a value.

exp

Computes an exponential value.

sqrt

Returns the square root of a value.

floor

Rounds a number down.

tan

Returns the tangent of a value.

log

Returns the natural logarithm of a value.

FLASH ACTIONSCRIPT QUICK REFERENCE

14

MOUSE OBJECT

You can use the methods of the Mouse object to show or hide the mouse. The table that follows lists the methods of the Mouse object and their purpose.

METHOD

PURPOSE

hide

Hides the cursor.

show

Shows the cursor.

MOVIECLIP OBJECT

You can use the methods of the MovieClip object to manipulate movie clips. The table that follows lists the methods of the Mouse object and their purpose.

METHOD

PURPOSE

METHOD

attachMovie

Attaches a movie clip in the Library and places it on the Stage.

loadVariables

Loads variables.

localToGlobal

Converts the Stage coordinates to global coordinates.

nextFrame

Sends the playhead to the next frame in the movie clip.

prevFrame

Sends the playhead to the previous frame in the movie clip.

removeMovieclip

Removes movie clips created with duplicateMovieClip and attachMovie from the Timeline.

startDrag

Makes a movie clip draggable.

stop

Stops a movie clip.

duplicateMovieClip Duplicates a movie clip. getBounds

Returns the boundaries of a movie clip.

getBytesLoaded

Returns the number of bytes loaded.

getBytesTotal

Returns the size of a movie clip.

getURL

Opens a Web page.

globalToLocal

Converts the Stage coordinates to local coordinates.

gotoAndPlay

Begins to play a movie clip in the frame specified.

gotoAndStop

Sends the playhead to a frame and stops the movie.

hitTest

Returns true if a movie clip touches or overlaps with another movie clip.

loadMovie

Loads a movie into a movie clip.

PURPOSE

stopDrag

Stops the drag actions.

swapDepths

Swaps the depth level of a movie clip.

unloadMovie

Removes a movie that was loaded using loadMovie.

291

FLASH ACTIONSCRIPT

NUMBER OBJECT

You can use the Number object to find the string value of a number or to return the primitive value of the Number object. The following table lists the methods of the Number object.

METHOD

PURPOSE

toString

Returns a number as a number.

valueOf

Returns the primative value of a number.

OBJECT OBJECT

You can use the Object object to find the string value of an object or to return the primitive value of the Object object. The following table lists the methods of the Object object.

METHOD

PURPOSE

toString

Returns the object as a string.

valueOf

Returns the primative value of an Object object.

SELECTION OBJECT

You can use the methods of the Selection object to control the text box that currently has focus. The following table lists the methods of the Selection object and their purpose.

292

METHOD

PURPOSE

getBeginIndex

Returns the index value of the beginning of a selection pan.

getCaretIndex

Returns the index value of the blinking cursor.

getEndIndex

Returns the index of the end of a selection pan.

getFocus

Returns the name of the variable for the text box that currently has focus.

setFocus

Sets the focus to specified text box.

setSelection

Sets the selection span.

FLASH ACTIONSCRIPT QUICK REFERENCE

14

SOUND OBJECT

You can use the methods of the Sound object to control sound. The table that follows lists the Sound methods and their purpose.

METHOD

PURPOSE

attachSound

Attaches a sound.

getPan

Returns the pan value.

getTransform

Returns the sound transform value.

getVolume

Returns the volume value.

setPan

Sets the pan value.

setTransform

Sets the transform value.

setVolume

Sets the volume.

start

Starts a sound.

stop

Stops a sound.

STRING OBJECT

You can use the String object to manipulate strings. The table that follows lists the methods of the String object and their purpose. METHOD

PURPOSE

charAt

Returns the character at a specified index position.

charCodeAt

Returns the numeric value of a character at a specified index position.

concat

Concatenates strings.

fromCharCode

Returns the character assigned to a code.

indexOf

Returns the first occurrence of the index value of a substring.

lastIndexOf

Returns the last occurrence of the index value of a substring.

slice

Returns a substring of a string.

substr

Returns a substring of a string. You specify the starting position and length.

substring

Returns a substring of a string. You specify the starting and ending position.

toLowerCase

Converts a string to lowercase.

toUpperCase

Converts a string to uppercase.

293

APPENDIX

WHAT’S ON THE CD-ROM

T

he CD-ROM disc included in this book contains many useful files and programs that can be used when working with Flash. You will find files that contain all the sample code used in this book, as well as several popular programs you can install on your computer. Before installing any of the programs on the disc, make sure that a newer version of the program is not already installed on your computer. For information on installing different versions of the same program, contact the program’s manufacturer.

SYSTEM REQUIREMENTS While most programs on the CD-ROM disc have minimal system requirements, your computer should be equipped with the following hardware and software to make the best use of all the contents of the CD-ROM disc: • A Pentium processor running Windows 95 or later or Windows NT 4 or later • At least 32 MB of available RAM • At least 40 MB of available disk space • Microsoft Internet Explorer 4.0 or later, or Netscape Navigator 4.0 or later recommended • 800 x 600 color display • CD-ROM drive

AUTHOR’S SOURCE CODE For Windows 2000. The CD provides files that contain all the sample code used throughout this book. You can browse these files directly from the CD-ROM, or you can copy them to your hard drive and use them as the basis for your own projects. To find the files on the CD-ROM, open the D:\RESOURCES\CODE folder. To copy the files to your hard drive, just run the installation program D:\RESOURCES\ CODE.EXE. The files will be placed on your hard drive at C:\ProgramFiles\FlashActionScript. After installing, you can access the files from the Start menu. You will need Flash 5 installed on the machine to run the samples. Please see Using Creative Techniques in Chapter 12 for more information.

ACROBAT VERSION The CD-ROM contains an e-version of this book that you can view and search using Adobe Acrobat Reader. You can also use the hyperlinks provided in the text to access all Web pages and Internet references in the book. You cannot print the pages or copy text from the Acrobat files. If you do

294

not currently have Adobe Acrobat Reader 5 installed, the computer will prompt you to install the software Acrobat files. A freeware version of Adobe Acrobat Reader is also included on the disc.

INSTALLING AND USING THE SOFTWARE This CD-ROM disc contains several useful programs. Before installing a program from the CD, you should exit all other programs. In order to use most of the programs, you must accept the license agreement provided with the program. Make sure you read any ReadMe files provided with each program.

Program Versions

Shareware programs are fully functional, free trial versions of copyrighted programs. If you like a particular program, you can register with its author for a nominal fee and receive licenses, enhanced versions, and technical support. Freeware programs are free, copyrighted games, applications, and utilities. You can copy them to as many computers as you like, but they have no technical support. GNU software is governed by its own license, which is included inside the folder of the GNU software. There are no restrictions on distribution of this software. See the GNU license for more details. Trial, demo, or evaluation versions are usually limited either by time of functionality. For example, you may not be able to save projects using these versions. For your convenience, the software titles on the CD are listed in alphabetic order.

Acrobat Reader

For Mac and Windows. Freeware. Acrobat Reader lets you view the online version of this book. For more information

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

on using Adobe Acrobat Reader, see page 296. From Adobe Systems, Inc., www.adobe.com.

Adobe Photoshop

For Mac and Windows. Trial Version. Enables you to create, edit, or retouch images. From Adobe Systems, Inc., www.adobe.com.

Dreamweaver 4

For Mac and Windows. Trial version. Enables you to quickly and easily develop HTML-based Web pages. From Macromedia, Inc., www.macromedia.com.

Dreamweaver UltraDev 4

For Mac and Windows. Trial Version. Enables you to develop Web pages that include ASP, JSP, or ColdFusion. From Macromedia, Inc., www.macromedia.com.

Flash 5

For Mac and Windows. Trial Version. Enables you to create interactive multimedia Web pages. From Macromedia, Inc., www.macromedia.com.

Flash Player

For Mac and Windows. Commercial version. Enables you to view Macromedia Flash content. From Macromedia, Inc., www.macromedia.com.

FreeHand 10

Stuffit Expander

For Mac. Commercial version. Enables users to access all downloads and attachments. From Aladdin Systems, www.aladdinsys.com.

Stuffit Lite

For Mac. Shareware. Enables you to compress files and open compressed files. From Aladdin Systems, www.aladdinsys.com/.

WinZip

For Windows. Shareware. Enables you to compress files and open compressed files. From Nico Mak Computing, Inc., www.winzip.com/.

TROUBLESHOOTING We tried our best to compile programs that work on most computers with the minimum system requirements. Your computer, however, may differ and some programs may not work properly for some reason. The two most likely problems are that you don’t have enough memory (RAM) for the programs you want to use, or you have other programs running that are affecting installation or running of a program. If you get error messages like Not enough memory or Setup cannot continue, try one or more of these methods and then try using the software again: • Close all running programs.

For Mac and Windows. Trial Version. Enables you to create vector-based illustrations for Flash and for print. From Macromedia, Inc., www.macromedia.com.

• Restart your computer.

Paint Shop Pro

• Add more RAM to your computer.

For Windows. Evaluation Version. Enables you to create, edit, or retouch images. From JASC Software, Inc., www.jasc.com/.

Director 8.5 Shockwave Studio

For Mac and Windows. Commercial version. Enables you to create multimedia content, including advanced 3D games. From Macromedia, Inc., www.macromedia.com.

• Turn off any anti-virus software. • Close the CD-ROM interface and run demos or installations directly from Windows Explorer. If you still have trouble installing the items from the CD-ROM, please call the Hungry Minds Customer Service phone number: 800-762-2974 (outside the U.S.: 317572-3994), or e-mail [email protected].

Shockwave

For Mac and Windows. Trial Version. Enables you to create multimedia content, including advanced 3D games. From Macromedia, Inc., www.macromedia.com.

295

APPENDIX

USING THE E-VERSION OF THE BOOK

Y

ou can view Flash ActionScript: Your visual blueprint for creating Flash-enhanced Web sites on your screen using the CD-ROM included at the back of this book. The CD-ROM allows you to search the contents of each chapter of the book for a specific word or phrase. The CD-ROM also provides a convenient way of keeping the book handy while traveling. You must install Adobe Acrobat Reader on your computer before you can view the book on the CD-ROM. This program is provided on the disc. Acrobat Reader allows you to view Portable Document Format (PDF) files, which can

display books and magazines on your screen exactly as they appear in printed form. To view the contents of the book using Acrobat Reader, insert the CD-ROM into your drive. The autorun interface will appear. Navigate to the eBook, and open the book.pdf file. You may be required to install Acrobat Reader 5.0 on your computer, which you can do by following the simple installation instructions. If you choose to disable the autorun interface, you can open the CD root menu and open the Resources folder, then open the eBook folder. In the window that appears, double-click the eBook.pdf icon.

USING THE E-VERSION OF THE BOOK

+

FLIP THROUGH PAGES

⁄ Click one of these options to flip through the pages of a section.

First page

ZOOM IN

Previous page

⁄ Click

Next page Last page

296

to magnify an area of the page.

¤ Click the area of the page you want to magnify.

■ Click one of these options to display the page at 100% magnification ( ) or to fit the entire page inside the window ( ).

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

To install Acrobat Reader, insert the CD-ROM disc into a drive. In the screen that appears, click Software. Click Acrobat Reader and then click Install at the bottom of the screen. Then follow the instructions on your screen to install the program. You can make searching the book more convenient by copying the .pdf files to your own computer. Display the contents of the CD-ROM disc and then copy the PDFs folder from the CD to your hard drive. This allows you to easily access the contents of the book at any time.

FIND TEXT

¤ Type the text you want to

⁄ Click

find.

to search for text in the section.

■ The Find dialog box

Acrobat Reader is a popular and useful program. There are many files available on the Web that are designed to be viewed using Acrobat Reader. Look for files with the .pdf extension. For more information about Acrobat Reader, visit the Web site at www.adobe.com/products/ acrobat/readermain.html.

■ The first instance of the text is highlighted.

› Click Find Again to find the next instance of the text.

‹ Click Find to start the search.

appears.

297

APPENDIX HUNGRY MINDS, INC. END-USER LICENSE AGREEMENT READ THIS. You should carefully read these terms and conditions before opening the software packet(s) included with this book ("Book"). This is a license agreement ("Agreement") between you and Hungry Minds, Inc. ("HMI"). By opening the accompanying software packet(s), you acknowledge that you have read and accept the following terms and conditions. If you do not agree and do not want to be bound by such terms and conditions, promptly return the Book and the unopened software packet(s) to the place you obtained them for a full refund. 1. License Grant. HMI grants to you (either an individual or entity) a nonexclusive license to use one copy of the enclosed software program(s) (collectively, the "Software") solely for your own personal or business purposes on a single computer (whether a standard computer or a workstation component of a multi-user network). The Software is in use on a computer when it is loaded into temporary memory (RAM) or installed into permanent memory (hard disk, CD-ROM, or other storage device). HMI reserves all rights not expressly granted herein. 2. Ownership. HMI is the owner of all right, title, and interest, including copyright, in and to the compilation of the Software recorded on the disk(s) or CD-ROM ("Software Media"). Copyright to the individual programs recorded on the Software Media is owned by the author or other authorized copyright owner of each program. Ownership of the Software and all proprietary rights relating thereto remain with HMI and its licensers. 3.

Restrictions On Use and Transfer.

(a) You may only (i) make one copy of the Software for backup or archival purposes, or (ii) transfer the Software to a single hard disk, provided that you keep the original for backup or archival purposes. You may not (i) rent or lease the Software, (ii) copy or reproduce the Software through a LAN or other network system or through any computer subscriber system or bulletin-board system, or (iii) modify, adapt, or create derivative works based on the Software.

298

(b) You may not reverse engineer, decompile, or disassemble the Software. You may transfer the Software and user documentation on a permanent basis, provided that the transferee agrees to accept the terms and conditions of this Agreement and you retain no copies. If the Software is an update or has been updated, any transfer must include the most recent update and all prior versions. 4. Restrictions on Use of Individual Programs. You must follow the individual requirements and restrictions detailed for each individual program in the What’s on the CD-ROM appendix of this Book. These limitations are also contained in the individual license agreements recorded on the Software Media. These limitations may include a requirement that after using the program for a specified period of time, the user must pay a registration fee or discontinue use. By opening the Software packet(s), you will be agreeing to abide by the licenses and restrictions for these individual programs that are detailed in the What’s on the CD-ROM appendix and on the Software Media. None of the material on this Software Media or listed in this Book may ever be redistributed, in original or modified form, for commercial purposes. 5.

Limited Warranty.

(a) HMI warrants that the Software and Software Media are free from defects in materials and workmanship under normal use for a period of sixty (60) days from the date of purchase of this Book. If HMI receives notification within the warranty period of defects in materials or workmanship, HMI will replace the defective Software Media. (b) HMI AND THE AUTHOR OF THE BOOK DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE, THE PROGRAMS, THE SOURCE CODE CONTAINED THEREIN, AND/OR THE TECHNIQUES DESCRIBED IN THIS BOOK. HMI DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION OF THE SOFTWARE WILL BE ERROR FREE.

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

(c) This limited warranty gives you specific legal rights, and you may have other rights that vary from jurisdiction to jurisdiction. 6.

Remedies.

(a) HMI’s entire liability and your exclusive remedy for defects in materials and workmanship shall be limited to replacement of the Software Media, which may be returned to HMI with a copy of your receipt at the following address: Software Media Fulfillment Department, Attn.: Flash ActionScript: Your visual blueprint for creating Flashenhanced Web sites, Hungry Minds, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, or call 1-800-762-2974. Please allow four to six weeks for delivery. This Limited Warranty is void if failure of the Software Media has resulted from accident, abuse, or misapplication. Any replacement Software Media will be warranted for the remainder of the original warranty period or thirty (30) days, whichever is longer.

8. General. This Agreement constitutes the entire understanding of the parties and revokes and supersedes all prior agreements, oral or written, between them and may not be modified or amended except in a writing signed by both parties hereto that specifically refers to this Agreement. This Agreement shall take precedence over any other documents that may be in conflict herewith. If any one or more provisions contained in this Agreement are held by any court or tribunal to be invalid, illegal, or otherwise unenforceable, each and every other provision shall remain in full force and effect.

(b) In no event shall HMI or the author be liable for any damages whatsoever (including without limitation damages for loss of business profits, business interruption, loss of business information, or any other pecuniary loss) arising from the use of or inability to use the Book or the Software, even if HMI has been advised of the possibility of such damages. (c) Because some jurisdictions do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation or exclusion may not apply to you. 7. U.S. Government Restricted Rights. Use, duplication, or disclosure of the Software for or on behalf of the United States of America, its agencies and/or instrumentalities (the "U.S. Government") is subject to restrictions as stated in paragraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause of DFARS 252.227-7013, or subparagraphs (c) (1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, and in similar clauses in the NASA FAR supplement, as applicable.

299

INDEX A absolute target path, 224–225 access [ ] operator, arrays, 162–163 Actions panel Colored Syntax colors, 27 comments, adding, 42–43 Expert mode, 24–27 fonts, sizing, 27 #include statement, 25 line, moving to, 27 modes, switching between, 26 movies, quality settings, 50–51 Normal mode, 24–27 open, 270 playhead, positioning, 48–49 scripts, printing, 27 Show Deprecated Syntax, 27 statements, 24–25, 27, 37 string characters, find/replace, 27 strings, search, 27 syntax errors, checking, 27 Toolbox list, 24–27 actions reference, 286 Actions statement, 24 actions appended with NUM, 280 argument association, 36 buttons, ActionScript definitions, 12 test, 38 ActionScript Actions panel, 24–27 argument, 36–37 AS file extension, 25 buttons action definitions, 12 assignment, 28 association, 6 code blocks, curly braces {and} characters, 36–37 comments, 42–43 expressions, 37 frames, assignment, 30–31 handlers, 28–29 #include statement, 25 keywords, case sensitive, 36

300

movie clips association, 6 assignment, 29 referencing by name, 19 movies, adding, 244 predefined objects, 144 smart clips, 18, 236–239 statements, 24–27, 36–37 static images, non-support, 8 view, 275 active layer, 4–5 Add a Statement button, 24, 26 Add Scene icon, 3 add comments, 42–43 numeric values, 112–113 scenes, 3 sounds, 16–17 addition (+) operator, 88, 100, 110 adjust, transparency, 68–69 alignments, 20–21 alpha, instances, 10–11 ampersand (&) character, bitwise AND, 100 AND (&&) operator, 132–133 animated buttons, 12, 19 animations buttons, 8 frame-by-frame, 14 movie clips conversion, 19 reusable, 8 preloader, 62 QuickTime, 32 start/end keyframes, 14 tween adjustments, 15 tweened, 14 antialiasing movie clip quality, 86–87 movie quality, 50–51 smoothing text, 21 arguments comma (,) character as separator, 36 defined, 36 parentheses (and) characters, 36 statements, 24 value assignments, 36

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

arrays access operator [ ], 162–163 comma (,) character as separator, 92 conversions, string, 174–175 create, 162–165 data types, 93 described, 162 display changes, 13 values, 273 elements adding, 168–169 assigning, 164–165 number (index), 162–163 removing, 170–171 value changes, 164–165 empty, 164–165 extract, 172–173 length, finding, 166–167 reverse, 172–173 arrow line, tween complete indicator, 15 Arrow tool, 6–7, 9, 11 AS file extension, 25 ASCII characters, URL-encoded conversion, 95 ASCII values, 198–200 assign, target paths, 224–225 assignments ActionScript, 28–31 variable values, 90–93 associations buttons, ActionScript, 6 dynamic text box/variables, 23 input text box/variables, 22 movie clips, ActionScript, 6 operator precedence, 111 asterisk (*) character, 22, 88, 116–117 asterisk (*) slash (/) characters, comments, 42 attach, movie clips, 148–151

B background images, symbol advantages, 9 backgrounds, 22–23 backslash (\) character, escape sequences, 91 Bandwidth Profiler, movie information display, 40–41 base 16, hexadecimal numbers, 177 base, numbers, 215 Basic Actions statement, 24

behaviors instances, 11 movie clips, selecting, 18 symbols, 9 BEST quality, movie clips, 86–87 binary operators, operands, 110 bitmap images, movies, printing as, 60 Boolean conversions, 108–109 data type, 88 primitive data type, 92 values, false, 56 borders, 22–23 boundary movie clip, 152–153 movie display, 33 brackets [and] characters, array access operator, 162–163 brightness, instances, 10–11 broken line, tween start indicator, 15 Brush tool, size/shape, 6 buttons ActionScript, 28 animated, create, 19 antialiasing on/off, 50–51 associations, ActionScript, 6 check mark beside, 13 convert to movie clip, 252 enable/disable, 13 execute continuous action, 252 four-frame Timeline, 12 handlers, 252, 283 images, importing, 13 instance behavior type, 11 interactive graphics, 8–9 keyframe, inserting, 13 movie clips, converting to panels, 260 movie startup point, 46 objects, dragging, 259 rotate continuously, 255 states, 12–13 stop action assignment, 44 tests, 13, 38 Timeline, 8–9

C Caps Lock key, Status bar display, 41 case sensitive, search limitation, 249

301

INDEX case, strings, changing, 106–107 CGI scripts, load/unload movies, 228–229 Change the Statement Order button, 24–25 change, colors, 176–177 characters string, extracting, 96–97 URL encoding, 278–279 check, frame load, 62–63 check mark, 13, , 27 child movie clips, parent placement, 234 circles, Oval tool, 6 Clip Parameters dialog box, 243 Clip Parameters panel, smart clips, 238–241 clocks, 184–185 code blocks comments, 42–43 curly braces {and} characters, 36–37 document with comments, 274 hexadecimal color, 280–282 panel size changes, 261 collision, detection, 158–159 color boxes, tools, stroke/fill, 6–7 Color object, movie clips, color change, 176–177 Colored Syntax, 27, 274 coloring book, create, 256–257 colors add to objects, 256–257 Colored Syntax, 27 comments, 27 deprecated syntax, 27 fill, 7 fonts, 20–21 hexadecimal codes, 280–282 hexadecimal values, 176–177 instances, 10–11 keywords, 27 magenta, comments, 42 mouse, change, 257 movie clips, changing, 176–177 predefined identifiers, 27 properties, 27 quoted strings, 27 statements, 27 stroke, 7 transform values, 178–179

302

columns, 5 comma (,) character argument separator, 36 array separator, 92 commands Control Debug Movie, 268 Loop Playback, 38 Mute Sounds, 38–39 Play, 38 Play All Scenes, 38 Rewind, 38 Step Backward, 38 Step Forward, 38 Test Movie, 38–40, 43, 261, 272–273 Test Scene, 38–39 Debug List Objects, 272 List Variables, 273 Edit Copy Frames, 18 Deselect All, 19 Edit Movie, 9 Edit Symbols, 9, 253 Paste Frames, 19 Select All, 19 File Import, 13, 16 Print, 61 Publish Preview, Default, 39 Publish Settings, 32, 50 Save, 38, 149 Insert Convert to Symbol, 9, 12, 219 Create Motion Tween, 14 Frame, 15 Keyframe, 13, 30 Layer, 4, 30 New Symbol, 8, 12–13, 18, 240 Modify Frame, 15 Instance, 11 Layer, 5 Transform, Edit Center, 73 Transform, Rotate, 73 Transform, Scale, 79 Options, Define Clip Parameters, 237

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

Text Character, 53 Options, 20–21 Paragraph, 21 View Antialias, 21 GoTo, 3 High Quality, 50 Magnification, 7 Quality, 41 Scene, 3 Show Streaming, 41 Zoom In, 7, 41 Zoom Out, 7, 41 Window Actions, 28–29, 31, 36, 41, 244, 246 Common Libraries, 237 Common Libraries, Learning Interactions, 241, 243 Controller (Mac), 39 Debug, 268 Library, 11, 237, 241–242 Movie Explorer, 222, 275 Output, 270 Panels, Clip Parameters, 239, 243 Effect, 11, 69 Fill, 7 Frame, 43 Instance, 11, 19, 66, 242 Mixer, 7 Scene, 3 Sound, 16 Stroke, 7 Text Options, 88 Toolbar, 41 Toolbar, Controller (PC), 39 Tools, 7 comments colors, 27 document code, 274 magenta color, 42 multiline, 42–43 single-line, 42–43 common library, smart clips, 259 communicate, Flash Player, 54–55 compound assignment operators, 130–131 compression, 16, 34

concatenate, strings, 100–101 conditional (?) operator, ternary type, 110 conditional checking, date validation, 246–247 conditional loops, 140–141 conditions, test, 134–135 constructors new Color, 176 new Date, 182–183, 186 new Sound, 202 newArray, 162, 166 continuous actions, start/stop, 252 Control menu, movies, testing, 38–39 Controller Toolbar, access methods, 39 convert array to string, 174–175 Booleans, 108–109 numbers, 108–109 string to number, 214–215 strings, 108–109 symbols, 252 coordinates, 160–161, 180 copy, selected objects, 6 counters, loops, 122 create animated buttons, 19 animations, 14–15 array, 162–165 buttons, trigger actions, 252–253 clocks, 184–185 coloring book, 256–257 colors, 7 custom functions, 220–221 draggable objects, 56–59 dynamic text box, 23 forms, 22 frame label, 31 gradients, 7 graphics, 6 input text boxes, 22 instance, 10–11 keyframes, 30 layers, 4–5, 30 menus, getURL action, 53 motion guide layers, 4 motion tween, 4 movie clips, 18–19 movies, one-frame, 252

303

INDEX objects, draggable, 258 rotation effects, 254–255 scenes, 2–3 scrollable text box, 218–219 smart clips, described, 236 sounds, 202–203 static text boxes, 20–21 symbol, 8–9 trigonometric special effects, 266–267 crop, movies, 33 curly braces {and} characters, code blocks, 36–37 curves, Pen tool, 6 custom functions, create, 220–221 custom interface, smart clips, 239–243

D data types array, 93 Boolean, 88 movie clip, 88 number, 88 object, 88 primitive, 92 reference, 92 string, 88 data, validate, 244–245 dates current, retrieving, 183 set, 186–187 update, 189 validate, 246–247 values, 188–189 retrieving, 184–185 days, validation, 246–247 debug, script, 274–275 Debugger display list, 223, 268 error correction, 268–269 movies, activating, 32 password protect movies, 269 Properties tab, changing property values, 268–269 status bar, 268 Variables tab, 268–269 Watch list, add/remove variables, 268–269 decimal places, round numbers, 194

304

decimal point (.), floating point numbers, 119 decrement (—) operator mathematical data type, 88 unary type, 110 set values, 124–125 Define Clip Parameters dialog box, 236–239, 243 delete layers, 4–5 selected objects, 6 statements, 24–25 Delete a Statement button, 25 Delete Scene icon, 3 deprecated syntax, display color, 27 depths, swap, 154–155 detect, collision, 158–159 device fonts movies, 34 static text boxes, 20–21 display list Debugger, levels/instances, 268 Flash Player, 222–223 divide, numeric values, 118–119 division (/) operator mathematical data type, 88 numeric values, dividing, 118–119 dot syntax, target path, 224–225 double hyphen (—) character, decrement operator, 88, 110, 124–125 double plus sign (++), increment operator, 88 double slashes (//) characters, single-line comments, 42 Down state, buttons, 12–13 downloads, frames, checking, 62–63 draggable objects create, 56–59 handlers, 58–59 scroll bars, 57 sound volume/pan, 57 Dropper tool, fill/stroke attributes, 6–7 duplicate movie clips, 234–235 scenes, 3 Duplicate Scene icon, 3 dynamic text invalid data entry, 244 variables, 88 dynamic text boxes, 23, 208–209

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

E editable text boxes, 20–21 Effect panels, instances adjustments, 11 _alpha property changes, 69 effects sounds, 16 spotlight, mask layers, 4 tweens, fading, 69 electronic coloring book, create, 256–257 elements, array adding, 168–169 assigning, 164–165 removing, 170–171 ellipses, Oval tool, 6 embedded fonts, static text boxes, 20–21 emulate panels, 258–261 Enable Simple Buttons, 38 Enable Simple Frame Actions, 38 equal sign (=) character, 65, 88 equality (==) operator, 128–129 equations, mathematical, 37 Eraser tool, 6 error messages date validation, 247 Options menu, Output Window, 270 to user, 245 errors, mathematical evaluation, 216–217 escape sequence characters, strings, 91 event sounds, 16 Event synchronization, sounds, 16 Events, ActionScript, handlers, 28–29 Expert mode Actions panel, 24–27 syntax checks, 275 exponentials, mathematical functions, 192 expression argument, 270 expressions argument, 36 convert, 108–109 defined, 37, 228 jumps, 48 mathematical equations, 37 operators AND (&&), 132–133 compound assignment, 130–131 equality (==), 128–129

greater than (>), 126 greater than or equal to (>=), 127 inequality (!=), 128–129 less than (=) operator, 127 group, selected objects, 6 guide layer, create, 4–5 guided layer, create, 4–5

H Hand tool, 7 handlers button, 252 draggable objects, 58–59 enterFrame, 262, 264, 266 event, selecting, 254 mouse, testing, 255 on (press), 28, 58–59 on (rollout), 58 on (dragOut), 28 on (dragOver), 28 on (keyPress, "key"), 28 on (release), 28 on (releaseOutside), 28 on (rollOver), 28 On Press, 258 on rollover, 53 onClipEvent (data), 29 onClipEvent (enterFrame), 29 onClipEvent (keyDown), 29 onClipEvent (keyUp), 29 onClipEvent (load), 29 onClipEvent (mouseDown), 29 onClipEvent (mouseMove), 29 onClipEvent (mouseUp), 29 onClipEvent (unload), 29 onClipEvent, 29 handles, objects, 73, 79 heights, movie clips, 75–76 hexadecimal color codes, 280–282

307

INDEX hexadecimal numbers, color selection, 256 hexadecimal values, colors, 176–177 hide layers, 4–5 mouse, 180 status bar, toolbox, 7 hierarchy, movies, 222–223 HIGH quality, movie clips, 86–87 HTML documents, templates, 34 HTML tags, 33 HTML Template Info dialog box, 34 hues, instances, 10–11 hyphen (-) character numeric values, subtracting, 114–115 subtraction operator, 88

I identifiers colors, 27 movie clip attachment, 148 images antialiasing, 50–51 background, 9 bitmap, printing movie as, 60 frame-by-frame animations, 14 static, 8 tweened frame animations, 14 import files, sounds, 16–17 images, buttons, 13 increment (++) operator mathematical data type, 88 unary type, 110 value setting, 122–123 indents, static text boxes, 21 index, array element number, 162–163 index position character string extraction, 96 substring extraction, 98 inequality (!=) operator, 128–129 infinity, mathematical error evaluation, 216–217 Ink Bottle tool, stroke line color/style, 6 input text boxes asterisk character password display, 22 backgrounds, 22 borders, 22

308

create, 22 forms, 22 HTML tag format, 22 multiline, 22 password, 22 single line, 22 text selections, 208–209 user input, 22 variable associations, 22 Word Wrap box, 22 insert, layers, 5 Insert Target Path dialog box, 230 Instance panel, movie clips, naming/renaming, 19, 66–67 instances behaviors, 11 movie clips naming, 19 targeting, 67 names, 66–67 symbols, 9–11 registration point, 73 instantiated objects, 144 integer numbers, 119 integers, numbers, rounding, 194 interactive graphics, ActionScript support, 8–9 interface, 2–3, 239–243 Internet Explorer, object tag, 33 Item Preview window, symbol preview, 9

J JavaScript, messages, passing with fscommand action, 55 JPEG graphics, quality adjustments, 32 jumps, 48

K key code vales, 276–277 keyboards, Key object, 198–201 keyframes, 13–14, 30 keys, movie startup point, 46 keywords case sensitive, 36 colors, 27 list, 279 this, 56, 225

FLASH ACTIONSCRIPT: Your visual blueprint for creating Flash-enhanced Web sites

L labels, frames, 31, 48 Lasso tool, object selection, 6–7 Layer Properties dialog box, 5 layers, 2, 4–5, 19, 30–31 Leap Year date validation, 246–247 modulo (%) operator determination, 120 occurrences, 247 Learning Interactions, Knowledge Tracks, 243 lengths, array, 166–167 less than (=), 127 if statement, 135 increment (++), 88, 122–123 inequality (!=), 128–129 less than (