Learning Flash
Learning Flash
Trademarks Add Life to the Web, Afterburner, Aftershock, Andromedia, Allaire, Animation PowerPack, Aria, Attain, Authorware, Authorware Star, Backstage, Bright Tiger, Clustercats, ColdFusion, Contribute, Design In Motion, Director, Dream Templates, Dreamweaver, Drumbeat 2000, EDJE, EJIPT, Extreme 3D, Fireworks, Flash, Flash Lite, Flex, Fontographer, FreeHand, Generator, HomeSite, JFusion, JRun, Kawa, Know Your Site, Knowledge Objects, Knowledge Stream, Knowledge Track, LikeMinds, Lingo, Live Effects, MacRecorder Logo and Design, Macromedia, Macromedia Action!, Macromedia Breeze, Macromedia Flash, Macromedia M Logo and Design, Macromedia Spectra, Macromedia xRes Logo and Design, MacroModel, Made with Macromedia, Made with Macromedia Logo and Design, MAGIC Logo and Design, Mediamaker, Movie Critic, Open Sesame!, Roundtrip, Roundtrip HTML, Shockwave, Sitespring, SoundEdit, Titlemaker, UltraDev, Web Design 101, what the web can be, and Xtra are either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned within this publication may be trademarks, service marks, or trade names of Macromedia, Inc. or other entities and may be registered in certain jurisdictions including internationally. Third-Party Information This guide contains links to third-party websites that are not under the control of Macromedia, and Macromedia is not responsible for the content on any linked site. If you access a third-party website mentioned in this guide, then you do so at your own risk. Macromedia provides these links only as a convenience, and the inclusion of the link does not imply that Macromedia endorses or accepts any responsibility for the content on those third-party sites. Speech compression and decompression technology licensed from Nellymoser, Inc. (www.nellymoser.com). Sorenson Spark video compression and decompression technology licensed from Sorenson Media, Inc.
Opera browser Copyright 1995-2002 Opera Software ASA and its suppliers. All rights reserved. Apple Disclaimer APPLE COMPUTER, INC. MAKES NO WARRANTIES, EITHER EXPRESS OR IMPLIED, REGARDING THE ENCLOSED COMPUTER SOFTWARE PACKAGE, ITS MERCHANTABILITY OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. THE EXCLUSION OF IMPLIED WARRANTIES IS NOT PERMITTED BY SOME STATES. THE ABOVE EXCLUSION MAY NOT APPLY TO YOU. THIS WARRANTY PROVIDES YOU WITH SPECIFIC LEGAL RIGHTS. THERE MAY BE OTHER RIGHTS THAT YOU MAY HAVE WHICH VARY FROM STATE TO STATE. Copyright 2004 Macromedia, Inc. All rights reserved. This manual may not be copied, photocopied, reproduced, translated, or converted to any electronic or machine-readable form in whole or in part without prior written approval of Macromedia, Inc. Acknowledgments Director: Erick Vera Project Management: Julee Burdekin, Erick Vera Writing: Jay Armstrong, Jody Bleyle, Mary Burger, Francis Cheng, Jen deHaan, Stephanie Gowin, Phillip Heinz, Shimul Rahim, Samuel R. Neff Managing Editor: Rosana Francescato Editing: Mary Ferguson, Mary Kraemer, Noreen Maher, Antonio Padial, Lisa Stanziano, Anne Szabla Production Management: Patrice ONeill Media Design and Production: Adam Barnett, Christopher Basmajian, Aaron Begley, John Francis Second Edition: June 2004 Macromedia, Inc. 600 Townsend St. San Francisco, CA 94103
CONTENTS
.................. 9
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Take a tour of the user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Change background and Stage size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Change your view of the Stage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 View the Library panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Add graphics to the Stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Add video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 View object properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Add video control behaviors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Use the Movie Explorer to view the document structure . . . . . . . . . . . . . . . . . . . . 19 Test the document. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Find help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
CHAPTER 2: Create Accessible Flash Content
. . . . . . . . . . . . . . . . . . . . . . . . . . 21
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Specify that your document be accessible to screen readers . . . . . . . . . . . . . . . . . . 22 Provide a document title and description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Provide a title and description for instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Specify that screen readers ignore elements in your document . . . . . . . . . . . . . . . . 23 Change static text to dynamic text for accessibility . . . . . . . . . . . . . . . . . . . . . . . . 24 Control the tab order and reading order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 About testing your document with screen readers . . . . . . . . . . . . . . . . . . . . . . . . . 26 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
. . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Create an instance of a symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Name button instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Initialize the document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 About ActionScript syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Locate ActionScript reference documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Add comments to ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Write a function for a button. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Copy and modify a button function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Check syntax and test your application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
CHAPTER 4: Create an Application
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Copy input and dynamic text fields. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Name text fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Add and name a Button component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Declare variables and values for the prices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Specify values for input text fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Write a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Write an event handler for the component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Test your application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
CHAPTER 5: Work with Layers .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Select a layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Hide and show layers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Lock a layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Add and name a layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Change the order of layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Organize layers in a folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Add a mask layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Add a guide layer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Delete a layer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
CHAPTER 6: Create a User Interface with Layout Tools
. . . . . . . . . . . . . . . . . . . 47
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Use guides to align an object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Change the Stage size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Resize objects to match the Stage size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Specify snap alignment settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Align an object using the alignment guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Align objects using the Align panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Snap objects to each other . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Contents
Align objects using the Property inspector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Align objects using the grid and arrow keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
CHAPTER 7: Draw in Flash .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Select a shape tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Select options to create a polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Draw a polygon. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Rotate the shape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Use the cut-out feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Transform the shape of your drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Copy strokes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Draw with the Line tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Select and add a different fill color. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Group the shape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Create a logo with the Pen tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
CHAPTER 8: Create Symbols and Instances
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 63 64 64 65 65 66 66 67 67
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About creating symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Create a graphic symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Duplicate and modify an instance of a symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . Modify a symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Create a movie clip symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assign an instance name to the movie clip. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Add an effect to the movie clip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CHAPTER 9: Add Animation and Navigation to Buttons
. . . . . . . . . . . . . . . . . . . 69 70 70 71 71 71 72 73 73 74 74 75
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Create a button from grouped objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Name a button instance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . View the hit area by enabling buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Change the hit area of a button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Align buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Create animation for a button state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Add an action to a button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Add navigation to a button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Test the SWF file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents
. . . . . . . . . . . . . . . . . . . . . . 77
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Create an expanding-width text block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Create a fixed-width text block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Edit text and change font attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Select device fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Add an input text field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Copy a text field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Assign instance names to text fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Create a dynamic text field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Specify format options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 View ActionScript for the dynamic text field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Test the SWF file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Check spelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
CHAPTER 11: Create a Timeline Animation .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Create a motion tween . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Create a shape tween . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Copy and paste keyframes in an animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Change the speed of the animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Test the SWF file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
CHAPTER 12: Create a Presentation with Screens (Flash Professional Only) .
. . 91
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 View the screen hierarchy and screen Timelines. . . . . . . . . . . . . . . . . . . . . . . . . . . 92 View screen properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Add content to a presentation slide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Add screen navigation behaviors to buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Add and name a slide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Select and move slides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Add content to a new slide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Add transition behaviors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Test your presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Contents
. . . . . . . . . . . . . . . . . . . . . . . . 97
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Name button instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Add a scene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Move between scenes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Control the document with a stop() action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Link a button to a scene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Add navigation to return to Scene 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Play a movie clip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Use a behavior to play an MP3 file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Test your document. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
CHAPTER 14: Create a Form with Conditional Logic and Send Data
. . . . . . . . 105
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Add an input text field to collect form data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Add a Submit button to the form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Add an error message. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Add a confirmation message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Add a stop() action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Add frame labels for navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Add conditional logic for the Submit button . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Pass data out of a SWF file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Write a function for the Try Again button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Test your SWF file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
CHAPTER 15: Work with Objects and Classes Using ActionScript 2.0 . . . . . . .
113
Set up your workspace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 About classes and object types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Creating an object from a class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Creating a custom class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Create two objects from the Product class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 About extending existing classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Extend the MovieClip class to create a new class . . . . . . . . . . . . . . . . . . . . . . . . . 120 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Contents
Contents
About the lessons The book includes several step-by-step lessons, designed to teach you the fundamentals of Flash. We recommend that you go through the lessons using the sample files provided. The path to the sample file is provided in each lesson. By completing these hands-on lessons, youll learn how to use Flash to add text, graphics, and animation to your Flash applications. Additionally, youll learn how easy it is to customize your Flash application by using ActionsScript and behaviors. The lessons are targeted toward beginners to intermediate-level Flash designers and developers who want to get up to speed quickly. Each lesson focuses on a specific Flash design feature or topic and takes approximately 1020 minutes to complete, depending on your experience. You can follow the lessons in this book in order, or you can start with a lesson or task that best suits your interests and experience. The Quick Start, Basic Flash, and Basic ActionScript lessons provide an opportunity to explore the Flash workspace. In these lessons, you learn how to create a Flash document, write ActionScript, work with video and video control behaviors, and add a Flash component.
Where to start If you are new to Flash, start with the Getting Started with Flash chapter in Help (Help > Help > Using Flash > Getting Started with Flash) to help you become familiar with Flash before proceeding to the Flash lessons. To complete the Flash lessons, you can follow the lessons in this book or open the lessons in the How Do I panel in Flash Help (Help > How Do I). Although the lessons can be completed in any order, the best way to build your understanding of Flash is to take the lessons in the order they appear in the How Do I panel. Typographical conventions The following typographical conventions are used in this book:
Menu items are shown in this format: menu name > menu item name. Items in submenus are
shown in this format: menu name > submenu name > menu item name.
Code font indicates HTML tag and attribute names as well as literal text used in examples. Italic code font indicates replaceable items (sometimes called metasymbols) in code. Bold roman text indicates text that you should enter verbatim. Additional resources for learning Flash
Flash contains a variety of media to help you learn the program quickly and become proficient in creating your own Flash applications. About the electronic manuals and lessons The following electronic manuals are available through the Help panel (Help > Help):
Getting Started with Flash (or Getting Started Help) provides a hands-on introduction to
Flash.
Using Flash (or Using Flash Help) contains complete information on working in the Flash
authoring tool, including all commands, features, and user interface elements.
Using ActionScript in Flash (or Using ActionScript Help) provides a conceptual introduction to
the ActionScript language
Flash ActionScript Language Reference (or Flash ActionScript Language Reference Help)
documents all actions, methods, and properties in the ActionScript API. If you are a new user, youll find the following information useful:
Getting Started with Flash (or Getting Started Help) provides basic information about the
Flash workspace and guides you in creating a simple document.
The lessons on the How Do I tab offer an introduction to using Flash. Refer to the Quick
Start, Basic Flash, and Basic ActionScript lessons (Help > How Do I).
10
Using the Help panel The updatable Help panel provides access to information on how to use Flash. For more information about the Help panel, see the following sections. Accessing help The tabs in the Help panelHelp and How Do Icontain the full set of user assistance information provided with the Flash application.
You can select the Help tab to display general help information. You can select the How Do I tab to display a list of 10- to 20-minute lessons that guide you
through many of the features in Flash.
To access help and the table of contents:
1. Select Help > Help to open the Help panel. 2. If the table of contents is not visible, click the Table of Contents button to display it.
The How Do I tab contains brief lessons that introduce you to the main features of Flash, letting you practice on isolated examples. If you are new to Flash, or if you have used only a limited set of features, start with the How Do I tab.
To start the lessons:
1. Select Help > How Do I to display the How Do I tab of the Help panel.
1. Click the Search icon in the Help panel toolbar. 2. Type a word or phrase in the text box, then click Search.
1. Click the Print button in the Help panel toolbar. 2. In the Print dialog box, select the printer and other printing options, then click Print.
11
Updating the Help panel The Update feature allows you to update your help system with new and revised documentation, including procedures and lessons. You can click the Update button to see if new information is available. Additionally, if you see a topic in help with the text For the latest information about this topic, click the Update button at the top of the Help tab, you can click this button to update Flash Help.
To update Flash Help:
1. Verify that youre connected to the Internet. 2. Click the Update button in the Help panel toolbar and follow instructions to download the
help system.
12
Youre about to experience the power of Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004. Youll see how, in a few minutes, you can create a compelling web experience that combines video, text, graphics, and media control behaviors. In the process, youll learn about the Flash authoring environment as you accomplish the following tasks:
Tour the user interface Dock and undock panels Change the background and Stage size Change your view of the Stage View your document library Add graphics to the Stage Add video View object properties Add video control behaviors Use the Movie Explorer to view the document structure Test the document Find help
Before taking this lesson, we recommend that you read Getting Started with Flash, to learn about the Flash workspace. To access this guide, select Help > Getting Started in Flash Help.
13
On Windows 2000 or XP, browse to boot drive\ Documents and Settings\All Users\Application Data\Macromedia\Flash MX 2004\language\Configuration\ HelpPanel\ HowDoI\ QuickTasks\start_files and double-click document_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\QuickTasks\start_files and double-click document_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/QuickTasks/start_files and double-click document_start.fla.
Note: The QuickTasks\finished_files folder contains completed versions of lesson FLA files, for your reference.
The document opens in the Flash authoring environment. The document already includes two layers in the Timeline. To learn more about layers, select Help > How Do I > Basic Flash > Work with Layers. One of the layers is a guide layer, which assists you in placing objects on the Stage. The other layer is a content layer in which to place the objects that will compose your document.
Note: Guide layers do not appear in the Flash content that you test or publish.
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
the original start file. As you complete this lesson, remember to save your work frequently. Select panel sets and arrange panels The Training Layout panel set arranges your workspace in a way that facilitates taking lessons. Youll use this layout for all lessons that you take in Flash.
You can undock a panel by clicking the upper left corner of the panel, in the Title bar, and dragging the panel to another location in the work area. If the panel snaps against a border, it is docked in a new location (or docked in the same location, if you moved it back). Otherwise, the panel is undocked.
You can resize an undocked panel by dragging the lower right edge out to enlarge the panel.
14
Use tools to create Flash content The white rectangular Stage area is where you can arrange objects as you wish them to appear in your published file.
Note: In Windows operating systems, you can open several documents at once and use document tabs, above the Stage, to navigate between them.
The Tools panel, next to the Stage, offers a variety of controls that let you create text and vector art. To learn more about Tools panel tools, select Help > How Do I > Basic Flash > Draw in Flash and Help > How Do I > Basic Flash > Add Static, Input, and Dynamic Text.
1. Click the Pencil tool in the Tools panel. Click the Stroke color box, in the Tools panel Colors
Youve created Flash content. Your finished document will be much more impressive. Undo actions Flash can undo a series of changes to your document. Youll undo the artwork that you just created.
1. To see the undo feature in action, first open the History panel (Window >
Other Panels > History). The Pencil tool appears in the panel, because using the tool was your last action.
2. Do one of the following:
Select Edit > Undo Pencil Tool. Press Control+Z (Windows) or Command+Z (Macintosh).
Your scribbles disappear from the Stage. The History panel now shows a dimmed Pencil tool, which indicates the undo action was executed. Flash, by default, is set to undo 100 of your changes, in reverse order of execution. You can change the default setting in Preferences. To change your preferences, see Setting Preferences in Flash in the Getting to Know the Workspace chapter of Getting Started with Flash (Help > Getting Started.
3. To close the History panel, click the options menu in the upper right corner of the panel and
select Close Panel. View the Timeline Just above the Stage, you see the Timeline and layers. You can create and name layers, then add content to frames on layers to organize how your Flash content plays as the playhead moves across the frames.
15
Move the mouse pointer over the area that separates the Stage from the Timeline. When the
resizing handle appears, drag up or down slightly to resize the Timeline as necessary.
The playhead (the red indicator line) is on Frame 1 in the Timeline. The keyframes are designated by small circles in the frames, which are filled, indicating theres content in those frames. You can add a keyframe to a document when you want the Flash content to change in some way in that frame.
background area of the Stage, so that no objects are selected. The Property inspector, below the Stage, displays properties for the document when no objects are selected.
3. To change the Stage background color, click the Background color box and select a light shade
Properties dialog box, enter 750 for the Stage width, then click OK. The Stage resizes to 750 pixels wide.
box, select 100% to view the Stage in dimensions that correspond to the size of the published Flash content.
16
selected, drag the Title movie clip, which contains a bitmap image and vector graphic, from the Library panel to the Stage and align it over the Title guide. In Flash, you can work with both bitmap images, which describe graphics using pixels, and vector art, which uses mathematical representation to describe art. For more information, see About vector and bitmap graphics in Using Flash.
2. With the Content layer still selected, drag the text symbol from the Library panel to Stage, and
align it with the Trio ZX2004 text thats already in place as a guide. You can use your keyboard arrow keys to nudge the text into place. The title text is actually a graphic created from text.
Add video
The Library panel includes an imported Flash video file (FLV). Youll add the video to your document, and Flash will add the necessary frames to play the video. To learn more about using video in Flash, see Working with Video in Using Flash.
1. Verify that the Content layer is still selected in the Timeline. From the Library panel, drag the
Click Yes.
3. Drag the playhead across the Timeline to view the video.
Add video
17
The Property inspector (Window > Properties) shows specifications, such as height, width, and Stage coordinates, for the grouped object.
2. On the Stage, click the bounding box for the video movie clip that you dragged to the Stage and
the Behaviors panel (Window > Development Panels > Behaviors), click the Add (+) button and select Embedded Video > Play. To learn more about symbols and instances, select Help > How Do I > Basic Flash > Create Symbols and Instances.
3. In the Play Video dialog box, verify that Relative is selected. Select video, which is the instance
name that you gave to the video clip, then click OK.
4. On the Stage, click the Pause movie clip instance to select it. In the Behaviors panel, click the
18
7. In the Rewind Video dialog box, select video. 8. In the Number of Frames to Step Back text box, enter 20.
The Number of Frames to Step Back text box indicates how many frames the playhead should move back when the user clicks the Rewind button.
Note: Additional video control behaviors let you fast-forward, hide, and show a video.
If necessary, enlarge the Movie Explorer to view the tree structure within the pane. The Movie Explorer filtering buttons display or hide information.
2. Click the pop-up menu in the title bar of the Movie Explorer, and select Show Movie Elements
are Show Buttons, Movie Clips, and Graphics; Show Action Scripts; and Show Video, Sounds, and Bitmaps. If you move your mouse pointer over a button, a tooltip displays the name of the button. Examine the list to view some of the assets included in the document, and to see their relationship to other assets.
4. In the Movie Explorer pane, expand Actions for Play to view ActionScript that Flash created
The Flash content plays in a SWF file window. While FLA is the extension for documents in the authoring environment, SWF is the extension for tested, exported, and published Flash content.
2. When you finish viewing the SWF content, close the SWF file window to return to the
authoring environment.
19
Find help
The lessons provide an introduction to Flash, and suggest ways that you can use features to create exactly the kind of document required. For comprehensive information about a feature, procedure, or process described in the lessons, see the Help tab of the Help panel (Help > Help).
Summary
Congratulations on creating a Flash document that includes graphics, a video, and video control behaviors. In a few minutes, you learned how to accomplish the following:
Tour the user interface Dock and undock panels Change the background and Stage size Change your view of the Stage View your document library Add graphics to the Stage Add video View object properties Add video control behaviors Use the Movie Explorer to view the document structure Test the document Find help
20
With knowledge of a few design techniques and accessibility features in Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004, you can create Flash content that is accessible to all users, including those with disabilities. This lesson demonstrates how to create an accessible document, designed for use with screen readers (which read web content aloud for visually impaired users) and other assistive technologies, as you accomplish the following tasks:
Specify that your document be accessible to screen readers Provide a document title and description Provide a title and description for document instances Specify that screen readers ignore elements in your document Change static text to dynamic text for accessibility Control the order in which users navigate with the Tab key Control the reading order with ActionScript
The lesson offers an introduction to basic techniques of making your Flash content accessible. For detailed and comprehensive information about incorporating accessibility features in your Flash content, see Creating Accessible Content in Using Flash.
21
On Windows 2000 or XP, browse to boot drive\ Documents and Settings\All Users\Application Data\Macromedia\Flash MX 2004\language\Configuration\ HelpPanel\ HowDoI\ QuickTasks\start_files and double-click accessibility_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\QuickTasks\start_files and double-click accessibility_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/QuickTasks/start_files and double-click accessibility_start.fla.
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
3. Select Window > Panel Sets > Training Layout to modify your workspace for taking lessons.
selected by default and allows Flash Player to pass accessibility information to a screen reader.
Make Child Objects Accessible allows Flash Player to pass accessibility information nested inside a movie clip to a screen reader. If this option is selected for the entire document, you can still hide child objects for individual movie clips. Auto Label associates text next to another Stage object, such as an input text field, as a label or
22
In the Name text box, enter Trio ZX2004. In the Description text box, enter Corporate
website about the Trio ZX2004. Includes 6 navigation buttons, overview text, and an animated car.
Trio Motor Company in the Name text box. Do not enter anything in the Description text box. Not every instance needs a description, which is read with the title information. If the title name sufficiently describes the function of the object, then you dont need to include a description.
2. With the Accessibility panel still open, select the Dealers button on the Stage.
Information in the Accessibility panel changes to reflect Accessibility options for the selected object. In the Accessibility panel for the Dealers button, you do not need to provide a name in the Title text box, because the button includes a text label that the screen reader will read. If you did not want the screen reader to read the text in the button, you could deselect Auto Label when you set up accessibility for the document.
3. In the Description text box, enter Links to a web page with information about
dealers nationwide. The other buttons also include text, which the screen reader will read aloud; therefore, you do not need to provide a title. Since the title of the buttons is fairly self-explanatory, theres no need for you to include descriptions.
23
1. On the Stage, click the car, which is the safety_mc movie clip instance. 2. In the Accessibility panel, deselect Make Child Objects Accessible. In the Name text box, enter
Trio ZX2004 animation. In the Description text box, enter Animation that includes three views of the Trio ZX2004.
efficiency ... The Accessibility panel changes to indicate that you cannot apply accessibility features to this selection.
2. In the Property inspector, select Dynamic Text from the Text Type pop-up menu.
24
If you have Flash MX Professional 2004, you can follow this procedure to create a tab order using the Accessibility panel:
1. With the Accessibility panel open, select the logo_mc instance at the top of the Stage. In the
5 text4_txt (the text above the Overview button that reads TRIO ZX2004) overview_btn powerplant_btn news_btn safety_mc text8_txt text9_txt 6 7 8 9 10 11
If you have Flash MX Professional 2004, follow this procedure to view a tab order:
Note: A tab order created with ActionScript, rather than the Accessibility panel, does not appear when Show Tab Order is enabled.
25
Follow this procedure to control the tab order and reading order using ActionScript:
1. In the Timeline, select Frame 1 of the Actions layer. 2. In the Actions panel (Window > Development Panels > Actions), view the ActionScript that
create the tab index using the Accessibility panel, delete the /* and */ in the script to uncomment the script:
_root.logo_mc.tabIndex = 1; _root.dealers_btn.tabIndex = 2; _root.orders_btn.tabIndex = 3; _root.research_btn.tabIndex = 4; _root.text4_txt.tabIndex = 5; _root.overview_btn.tabIndex = 6; _root.powerplant_btn.tabIndex = 7; _root.news_btn.tabIndex = 8; _root.safety_mc.tabIndex = 9; _root.text8_txt.tabIndex = 10; _root.text9_txt.tabIndex = 11; _root.bevel_mc.tabIndex = 12;
Summary
Congratulations on creating accessible Flash content. In a few minutes, you learned how to accomplish the following tasks:
Specify that your document be accessible to screen readers Provide a document title and description Provide a title and description for document instances Specify that screen readers ignore elements in your document Change static text to dynamic text for accessibility Control the order in which users navigate with the Tab key Control the reading order with ActionScript
Macromedia maintains an extensive website devoted to accessibility. For more information about accessibility with Macromedia products, see the Macromedia accessibility website at www.macromedia.com/macromedia/accessibility.
26
The ActionScript language that is part of Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 offers designers and developers a variety of benefits. With ActionScript you can control document playback in response to events such as elapsed time and loading data; add interactivity to a document in response to user actions, such as a button click; use built-in objects, such as a button object, with built-in associated methods, properties, and events; create custom classes and objects; and create more compact and efficient applications than you could create using user interface tools, all with code that you can reuse. ActionScript is an object-oriented scripting language that offers control over how your Flash content plays. In subsequent lessons, youll see how ActionScript has evolved into ActionScript 2.0 to comprise a core set of language elements that make it easier to develop object-oriented programs. Youll now use ActionScript to accomplish the following tasks:
Name instances following recommended practices Initialize a document Apply ActionScript syntax Locate ActionScript reference documentation Add comments to ActionScript Write a function Copy and modify a function Check syntax and test your application
27
On Windows 2000 or XP, browse to boot drive\ Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\ HelpPanel\ HowDoI\ QuickTasks\start_files and double-click scripts_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\QuickTasks\start_files and double-click scripts_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/QuickTasks/start_files and double-click scripts_start.fla.
Note: The QuickTasks\finished_files folder contains completed versions of lesson FLA files, for your reference.
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
of the Stage. Because guides dont appear when you first drag an object from the Library panel, youll release the object and then drag it again.
28
4. Drag the map_skewed movie clip on the Stage again so that the align guides appear. Use the
guides to align the movie clip to the top and left edges of the GPS screen.
Note: If you make an error in placement, either drag the movie clip again, or press Control+Z (Windows) or Command+Z (Macintosh) to undo your changes.
5. With the instance of map_skewed selected on the Stage, type screen_mc in the Instance Name
Flash is designed to present code hints when you name your instances with the appropriate suffix:
When naming a movie clip instance, always give the instance a suffix of _mc, as in screen_mc. When naming a button, use the _btn suffix. When naming a text field, use the _txt suffix.
Note: For more information about additional instance name suffixes that prompt code hints, see Writing code that triggers code hints in Using ActionScript in Flash.
the instance.
4. On the Stage, select the instance of button_stop (the small red button). 5. In the Instance Name text box of the Property inspector, type offButton_btn to name
the instance.
29
Development Panels > Actions. Actions - Frame appears at the top of the panel, which indicates that you selected a frame in which to apply ActionScript. Its a good practice to verify that youre attaching ActionScript to the intended frame or object. The Actions panel includes a Script pane, the blank text entry area, in which you can enter text directly; an Actions toolbox, which lets you select ActionScript to add to your script; and a Script navigator, which functions like the Movie Explorer.
2. Along the top of the Actions panel, click Insert Target path. 3. In the Insert Target Path dialog box, verify that Relative, meaning relative path, is selected.
From the hierarchical tree in the dialog box, select screen_mc. Then click OK. A target path tells ActionScript the location of an object within the overall structure of a document. For more information about paths, see Using absolute and relative target paths in Using Flash.
4. Click in the Script pane, at the end of the screen_mc text, and type a period (.). 5. When you type the period, code hints appear for the movie clip, because you used the _mc suffix
when naming the instance. Double-click _visible from the list of code hints, and type the following:
= false;
This line of code makes the screen_mc movie clip invisible on the Stage.
Note: If code hints dont appear, you dont have code hints selected as a preference in the Actions panel. You can type _visible directly in the Script pane. You can also change your preferences by clicking the options menu in the upper right corner of the Actions panel. From the options menu, select Preferences, and then select Code Hints on the ActionScript tab.
Parentheses () group arguments that apply to an ActionScript statement. Curly braces {} group related ActionScript statements. You can use nested braces to create a
hierarchy of statements.
30
Later in this lesson, youll use Flash features that allow you to test your syntax.
2. Along the top of the Actions panel, click the Reference icon.
In the Script pane of the Actions panel, place the insertion point at the beginning of the line
of code and type //Initialize document to hide screen movie clip. Press Enter or Return. Text in the Script pane appears as follows:
//Initialize document to hide screen movie clip. this.screen_mc._visible = false; Note: If your commented text is many lines, you can use /* instead of double slashes for the beginning of the comment, and */ to mark the end of the comment.
that appears.
31
4. In the Script pane, press the Spacebar and type the following:
= function(){
The line of code that you just completed should appear as follows:
this.onButton_btn.onRelease = function(){
You already know how to select objects in the Insert Target Path dialog box; youll now enter the instance names directly into the Script pane.
5. Press Enter or Return and type the following:
screen_mc._visible = true;
6. Press Enter or Return and type }; to specify the end of the statement.
brackets, and semicolon. Copy the text as you normally would, using Control+C (Windows) or Command+C (Macintosh).
2. In the Script pane, place the insertion point after the last line of code. Then press Enter or
Return twice, and paste the text as you normally would, using Control+V (Windows) or Command+V (Macintosh).
3. In the copied function, change the text in onButton_btn to read offButton_btn.
to false.
5. In the copied function, change the commented text after the slashes to read function to
hide animation.
32
Click the options menu in the upper right corner of the Actions panel title bar and select Check Syntax. Click the Check Syntax button along the top of the Actions panel.
If the syntax is correct, a message appears stating that the script contains no errors. If the syntax is incorrect, a message appears stating the script contains errors; the Output panel opens and displays information about the error.
2. Click OK to close the syntax message. 3. After youve verified that your ActionScript does not contain syntax errors, save the document
and select Control > Test Movie. When the SWF file appears, the animation should not appear in the Global Positioning System screen, because its initial visible property is set to false. When you click and release the top green button, you call the function that sets the movie clips visible property to true. Does the animation play then? Finally, click the red Off button to see if the visible property for the animation is again false. You can test your SWF content throughout authoring to confirm that it plays as expected.
Summary
Congratulations on learning a few basics about writing scripts with ActionScript. In a short amount of time, you learned how to accomplish the following tasks:
Name instances following recommended practices Initialize a document Apply ActionScript syntax Locate ActionScript reference documentation Add comments to ActionScript Write a function Copy and modify a function Check syntax and test your application
To learn more about ActionScript, select Help > How Do I > Quick Tasks > Create an Application.
Summary
33
34
The application that youll create in this lesson lets users view the cost of selecting multiple products. A Calculate button then adds the total cost. Youll learn how to accomplish the following tasks as you create the application:
Copy input and dynamic text fields Assign instance names to text fields Add a Button component Declare variables and values Specify values for text fields Write a function Write an event handler for the component
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\QuickTasks\start_files and double-click calculator_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\QuickTasks\start_files and double-click calculator_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/QuickTasks/start_files and double-click calculator_start.fla.
Note: The QuickTasks\finished_files folder contains completed versions of lesson FLA files, for your reference.
35
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
3. Select Window > Panel Sets > Training Layout to modify your workspace for taking lessons.
The form already includes an input text field in the QTY column and a dynamic text field in the Price column. Youll copy the text fields for the Shocks and Cover rows.
2. Alt-click the input text field that you just dragged; then drag the new copy of the field to the
qty3_txt, respectively.
3. Click the top dynamic text field in the Price column. In the Instance Name text box of the
36
1. Select File > Publish Settings. 2. On the Flash tab of the Publish Settings dialog box, select ActionScript 2.0 in the ActionScript
Button component to the Stage and place it over the Calculate guide.
5. On the Parameters tab of the Property inspector, with the Button component selected, click the
Button text on the Label row, and type Calculate. Then press Enter or Return. The text that you type in the Label text box is the text that appears on the component.
6. In the Instance Name text box, enter calculate to provide the button with an instance name.
The parallel slashes (//) indicate that the text that follows is a comment. As a best practice, always add comments that offer an explanation of your ActionScript.
Note: As you take this lesson, you might find that youd like to turn off code hintsthe tooltips that prompt you with the correct ActionScript syntax. If so, you can turn off code hinting by clicking the options menu in the upper right corner of the Actions panel. Select Preferences, and then deselect Code Hints on the ActionScript tab.
3. Press Enter or Return and type the following to indicate the cost of each part:
var priceCD = 320; var priceShocks = 150; var priceCover = 125;
is the instance name that you gave the first input text field under the QTY column. is a property that defines the initial value in the text field, which you specify is 0.
37
3. Press Enter or Return and type the following two lines to set values of 0 for the other two
QTY fields:
qty2_txt.text = 0; qty3_txt.text = 0;
Write a function
A function is a script that you can use repeatedly to perform a specific task. You can pass parameters to a function, and it can return a value. In this lesson, every time your user clicks the Calculate button, a function will run that multiplies data in the input text fields and returns values in the dynamic text fields. Youll write that function now.
1. In the Script pane, with the insertion point after the ActionScript that reads qty3_txt.text =
0;,
2. Press Enter or Return and type the following to create a function that runs when the playhead
3. Type the following ActionScript to specify how the function should multiply the values in the
is the instance name that you gave to the top price input text field on the Stage.
defines the text that should appear in the text field, which is the number of parts multiplied by the cost of the part: the $320 that you set as the value for the priceCD variable.
38
The tab at the bottom of the Actions panel, labeled calculate, indicates that youre attaching the script directly to the selected object rather than to a frame.
2. In the Script pane, type the following comment:
//Calculates total price
3. After the comment, press Return or Enter and type the following to create a handler for the
You just typed the start of the on() event handler. The (click) specifies that the event should occur when the user clicks the Calculate button. A Button component has its own Timeline. In the Timeline hierarchy, the component Timeline is a child of the main Timeline. To point to elements from the Button component Timeline to the main Timeline in this script, you use the code with (_parent).
4. With the insertion point at the end of the line you just typed, press Enter or Return and type
the following:
with(_parent){
5. Press Enter or Return and complete your handler by typing the following:
priceTotal_txt.text = Number (price1_txt.text) + Number (price2_txt.text) + Number (price3_txt.text); } }
The event handler that you typed specifies that the text in the priceTotal_txt field should be the sum of the values in the Price1_txt, Price2_txt, and Price3_txt fields.
39
Summary
Congratulations on learning how to create an application. In a few minutes, you learned how to complete the following tasks:
Copy input and dynamic text fields Assign instance names to text fields Add a Button component Declare variables and values Specify values for text fields Write a function Write an event handler for the component
To learn more about ActionScript, take a lesson in the Basic ActionScript series on the How Do I tab of the Help panel.
40
In Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004, layers are analogous to transparent sheets of acetate stacked on top of each other. In the areas of a layer that dont contain content, you can see through to content on the layers below. Layers assist you in organizing content in your document. For example, you can keep background art on one layer and navigational buttons on another. Additionally, you can create and edit objects on one layer without affecting objects on another layer. In this lesson, youll learn about layers as you accomplish the following tasks:
Select a layer Hide and show layers Lock a layer Add and name a layer Change the order of layers Organize layers in a folder Add a mask layer Add a guide layer Delete a layer
41
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\ HelpPanel\ HowDoI\BasicFlash\start_files and double-click layers_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicFlash\start_files and double-click layers_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicFlash/start_files and double-click layers_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
Timeline view. You can also use the scroll bar to scroll through the layers.
42
Select a layer
You place objects, add text and graphics, and edit on the active layer. To make a layer active, you either select the layer in the Timeline or select a Stage object in the layer. The active layer is highlighted in the Timeline, and the pencil icon indicates it can be edited.
1. In the Tools panel, click the Selection tool. 2. On the Stage, select the red car.
A pencil icon in the Timeline indicates that the Red Car layer is now the active layer.
3. Select the Text layer in the Timeline.
The text blocks above and below the red car are both selected on the Stage, since theyre both on the Text layer.
the Stage. Controls to the right of each layer name let you show or hide the contents of a layer.
Note: You may need to use the scroll bar to see all the layers.
Lock a layer
When youve placed content as desired on a layer, you can lock the layer to avoid inadvertent changes to the content by you or by others working on the document.
1. In the Timeline, click the black dot under the Lock column, next to the Logo layer.
Lock a layer
43
The new layer appears above the Car layer and becomes the active layer.
3. Double-click the layer name, type Background as the new name for the layer, and press Enter
(Windows) or Return (Macintosh). As a best practice, always name each layer, and give the layer a meaningful name that indicates the type of content on the layer.
4. In the Library panel (Window > Library), select the background graphic symbol and drag it to
the Stage. Because the Background layer is above all layers except the Mask layer, objects on that layer appear over objects on lower layers.
and 72 in the Y text box. Press Enter or Return to precisely position the Background layer on the Stage.
3. Double-click the layer folder name and rename the folder Navigation. 4. Drag the Navbar layer and the Buttons layer to the Navigation folder.
The layers appear indented to indicate that theyre within the folder. You can click the expander arrow to expand and collapse the folder and included layers.
44
Mask from the context menu. The layer converts to a mask layer, indicated by a blue diamond-shaped icon. The layer immediately below the layer is linked to the mask layer. The masked layers name is indented, and its icon changes to a blue layer icon.
4. In the Timeline, drag the Road layer to the Mask layer, placing it below the Car layer.
The mask layer and the layers it masks are automatically locked.
5. To view the mask effect, select Control > Test Movie. 6. When you finish viewing the mask effect, close the SWF file window to return to
your document.
new layer.
2. Name the new layer Notes and press Enter or Return. 3. Right-click (Windows) or Control-click (Macintosh) the Notes layer and select Guide from the
context menu. An icon next to the layer name indicates that the layer is a guide layer.
4. With the Notes layer still selected, click the Text tool in the Tools panel. Then, in the area of
the Stage above the car and road, enter Production note: Animation with no stop (); actions loop by default.
5. Save your document and select Control > Test Movie.
No content that you added to the guide layer appears in the SWF file window.
6. When you finish viewing the SWF file, close the window to return to the document.
45
Delete a layer
Since you dont really need the guide layer in your document, youll delete it.
In the Timeline, with the Notes layer selected, click the Delete Layer button. Summary
Congratulations on learning how to work with layers in Flash. In just a few minutes, you learned how to accomplish the following tasks:
Select a layer Hide and show layers Lock a layer Add and name a layer Change the order of layers Organize layers in a folder Add a mask layer Add a guide layer Delete a layer
46
Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 offer a variety of ways to place objects precisely on the Stage, letting you choose your preferred method. In this lesson, youll use layout tools to create a user interface. Specifically, youll accomplish the following tasks:
View the workspace rulers Use guides to align objects Change the Stage size Resize objects to match the Stage size Align an object using the alignment guides Align objects using the Align panel Snap objects to each other Align objects using the Property inspector Use the grid and arrow keys to align objects
Although this lesson uses specific tools for particular types of objects (alignment guides to align text, for example), no strict rules exist about the best way to align a particular type of object. In your own projects, use whatever tools suit your needs.
47
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicFlash\start_files and double-click layout_tools_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicFlash\start_files and double-click layout_tools_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicFlash/start_files and double-click layout_tools_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
A horizontal and vertical ruler appear above and to the left of the Stage.
2. Click anywhere in the horizontal ruler and drag down until you reach the 250-pixel
horizontal position.
3. Click anywhere in the vertical ruler and drag left until you reach the 375-pixel vertical position. 4. In the Tools panel, click the Selection tool.
48
5. On the Stage, click the upper left corner of the text block and drag it to the intersection of the
two guides.
click OK. The document size changes, but the objects on the Stage remain the same size.
Tooltips appear in the Align panel showing the names of alignment options.
3. In the Align panel, select To Stage; then, under Match Size, select Match Width. The size of
49
Snap tolerance determines how close an object must be to another object or alignment tool before it snaps into place.
5. Click OK.
the body text, and up and down as necessary until the center alignment guide appears, which indicates the auto is centered in relation to the body text.
50
5. While keeping the car centered with the body text (you should continue to see the center
alignment guide), drag the auto in a straight line, toward the left of the Stage, until the guide snaps at the 30-pixel border that you created previously.
Youve aligned the car with the text, as well as to the snapping border.
Hybrid 4WD.
2. Press the Shift key and click the second line of title text, 2004 Trio QZ, to add it to
the selection.
3. In the Align panel (Window > Design Panels > Align), deselect To Stage and select Align
Horizontal Center. Youve centered the two rows in relation to their horizontal axes. Next, youll group the title text to center both lines in relation to the Stage.
4. With both lines of text still selected, select Modify > Group. 5. In the Align panel, select To Stage, then select Align Horizontal Center again.
With To Stage selected, the objects align in relation to the horizontal center of the Stage.
6. Close the Align panel.
51
3. From the Library panel, drag the nav graphic to any area of the Stage below the blue banner,
4. Click the upper left corner of the nav graphic, then drag it so that a circular snap indicator
appears.
5. With the snap indicator visible, drag the upper left corner of the nav bar and snap it into place
3. In the Property inspector, with the logo still selected, enter 20 in the X text box and 8 in the Y
text box. Press Enter or Return. The logo moves to the new x and y Stage values.
Note: You can view and change the registration point of an object in the Info panel (Window > Design Panels > Info). The black square in the grid represents the registration point. To change it, you click another square in the grid.
52
The grid does not appear when you test or publish your document.
Note: If you wanted to snap objects to the horizontal and vertical grid lines, you would also select Snap to Grid (View > Snapping > Snap to Grid). For this lesson, you wont snap objects to the grid.
2. On the Stage, select the title text you previously grouped together. 3. Use the Up Arrow key on your keyboard to nudge the text until the first line in the title text is
on a horizontal grid line. Be sure to leave space between the title text and the navigation bar.
Note: You can also use the Left Arrow, Down Arrow, and Right Arrow keys to nudge objects on the Stage in the direction of the arrow.
Summary
Congratulations on using layout tools to create a user interface. In a few minutes, you learned how to accomplish the following tasks:
View the workspace rulers Use guides to align objects Change the Stage size Resize objects to match the Stage size Align an object using the alignment guides Snap objects to each other Align objects using the Property inspector Use the grid and arrow keys to align objects
For more information about design topics in Flash, take another lesson from the Basic Flash series.
Summary
53
54
When you draw in Flash, you create vector art, which is a mathematical representation of lines, curves, color, and position. Vector art is resolution-independent; you can rescale the art to any size or display it at any resolution without losing clarity. Additionally, vector art downloads faster than comparable bitmap images. In this lesson, youll create vector art of a bolt and logo as you accomplish the following tasks:
Create a polygon Rotate a shape Cut out a shape within a shape Transform artwork Copy strokes Draw lines with the Line tool Select and add a fill color Group a shape Create a logo with the Pen tool
55
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicFlash\start_files and double-click drawing_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicFlash\start_files and double-click drawing_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicFlash/start_files and double-click drawing_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
the original start file. As you complete this lesson, remember to save your work frequently.
3. Select Window > Panel Sets > Training Layout to configure your workspace.
the Rectangle tool to see a menu that displays the PolyStar tool.
3. Click anywhere in the gray work area beside the Stage to display properties for the shape youll
create. In the Property inspector (Window > Properties), verify that black is selected as the stroke color, 1 pixel is selected as the stroke height, and Solid is selected as the stroke style. The stroke is the line that outlines your shape.
4. Click the Fill Color control and select blue with a hexadecimal value of #0000FF.
56
Draw a polygon
The Shift key assists you in constraining your shape along a vertical or horizontal line.
Press Shift and drag the mouse over the left side of the Stage (away from the numbers on the
Guides layer) to draw a hexagon, as shown in the following illustration:
select both the stroke and the fill. Clicking just once within a shape selects only the fill.
2. Select Window > Design Panels > Transform. In the Transform dialog box, verify that Rotate
is selected, and enter -15 in the Rotate text box to rotate the shape 15 clockwise. Press Enter or Return.
57
within the hexagon (imagine the hexagon as the face of a clock and begin your circle at the 10:00 corner point, dragging to the 4:00 corner point), as in the following illustration.
Note: If you make an error drawing the circle, press Control+Z (Windows) or Command+Z (Macintosh) to undo your circle.
3. In the Tools panel, click the Selection tool. On the Stage, click within the circle and press
Backspace or Delete.
following shape:
58
Copy strokes
You can select and copy strokes, which youll do now to create the lower edge of the bolt.
1. With the Selection tool, click anywhere on the Stage or work area, away from an object, to
3. Press Shift + Alt and drag down slightly to drag a copy of the three lines, as in the
following illustration:
In the Tools panel, select the Line tool. On the Stage, draw four vertical lines from the hexagon
to the stroke copies that you dragged down, as shown in the following illustration:
59
3. Click the dot next to the number 3 and next to the number 4 in sequence (as though you were
completing a dot-to-dot drawing) to create the straight line segments that comprise the logo.
4. To close the path, position the Pen tool over the first anchor point (the dot by number 1). A
small circle appears next to the pen tip when it is positioned correctly. Click to close the path. Once the path is closed, it fills with the selected fill color. By default, selected curve points appear as hollow circles, and selected corner points appear as hollow squares.
5. With the Selection tool, move the pointer around the logo that you created.
When you move the pointer over a corner point, which you can click and drag to create various angles, the pointer appears as follows:
When you move the pointer over a curved line segment (you dont have curve points in your logo), which you can click and drag to create various curved lines, the pointer appears as follows:
60
Summary
Congratulations on learning how to use some of the various drawing tools in Flash. In a few minutes, you learned how to accomplish the following tasks:
Create a polygon Rotate a shape Cut out a shape within a shape Transform artwork Copy strokes Draw lines with the Line tool Select and add a fill color Group a shape Create a logo with the Pen tool
To learn more about creating art in Flash, see Drawing in Using Flash.
Summary
61
62
A symbol is a reusable object, and an instance is an occurrence of a symbol on the Stage. Repeated use of instances does not increase the file size and is a good part of a strategy for keeping a document file size small. Symbols also simplify editing a document; when you edit a symbol, all instances of the symbol update to reflect the edits. Another benefit of symbols is that they allow you to create sophisticated interactivity. In this lesson youll work with symbols and instances to accomplish the following tasks:
Create a graphic symbol Duplicate and modify an instance Create a movie clip symbol Edit a symbol by adding an effect
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicFlash\start_files and double-click symbols_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicFlash\start_files and double-click symbols_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicFlash/start_files and double-click symbols_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
63
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
the original start file. As you complete this lesson, remember to save your work frequently.
3. Select Window > Panel Sets > Training Layout to configure your workspace.
3. Select Modify > Convert to Symbol. 4. In the Convert to Symbol dialog box, enter CarGraphic as the name and select Graphic as
the behavior.
5. The Registration grid uses a small black square to indicate where, within the symbol bounding
box, the registration point is located. A registration point is the axis around which the symbol rotates, and the point along which the symbol aligns. Click the upper left square on the grid to select the registration point location, and click OK.
6. The car on the Stage is now an instance of the CarGraphic symbol. The Property inspector
7. Open the Library panel (Window > Library) to view the symbol.
Youll find the CarGraphic symbol in the Library panel. Flash stores symbols in the library. Each document has its own library, and you can share libraries between different FLA files.
64
2. With the duplicate selected, select Tint from the Color pop-up menu in the Property inspector. 3. In the RGB area, enter 0 in the Red Color pop-up menu, 0 in the Green Color pop-up menu,
and 255 in the Blue Color pop-up menu. Then press Enter or Return. The duplicate instance turns blue, but the original instance remains unchanged.
Modify a symbol
You can enter symbol-editing mode by double-clicking any instance of a symbol. Changes that you make in symbol-editing mode affect all instances of the symbol.
1. Do one of the following to enter symbol-editing mode:
On the Stage, double-click one of the car instances. In the Library panel, double-click the CarGraphic symbol.
Next to Scene 1 toward the top of the workspace, the name of the symbol appears, which indicates that youre in symbol-editing mode for the named symbol.
2. In the Tools panel, select the Free Transform tool and drag around the bottom car to select the
entire car. In symbol-editing mode, the car is a graphic, within a symbol, that you can manipulate as you would any other vector graphic.
Modify a symbol
65
3. Drag the middle-right sizing handle of the Free Transform tool slightly to the right, to stretch
the symbol.
to Symbol.
2. In the Convert to Symbol dialog box, enter MCWheel as the name, and select MovieClip as
the behavior.
3. In the Registration grid, this time select the center square as the registration point, so the center
of the movie clip becomes the axis around which the symbol rotates. Then click OK. The image on the Stage is now an instance of the MCWheel symbol in the library.
In the Property inspector, with the instance of MCWheel selected on the Stage, enter
wheel_mc in the Instance Name text box.
66
Summary
Congratulations on learning about symbols and instances. In a few minutes, you accomplished the following tasks:
Create a graphic symbol Duplicate and modify an instance Create a movie clip symbol Edit a symbol by adding an effect
To learn more about Flash, take another lesson in the Basic Flash series.
Summary
67
68
A button is a symbol that contains special frames for different button states, such as when the users mouse pointer is over the button or when the user clicks the button. When you select the Button behavior for a new symbol, Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 create the Timeline for the button states. You can add navigation to buttons by using behaviors or by writing ActionScript. In this lesson, youll learn about creating and modifying buttons, including adding animation to a button. Specifically, youll learn how to complete the following tasks:
Create a button from grouped objects Name a button instance View the hit area of a button Change the hit area of a button Align buttons Create animation for a button state Add an action to a button Add navigation to a button
If you are not familiar with symbols and instances, before taking this lesson select Help > How Do I > Basic Flash > Create Symbols and Instances to take that lesson.
69
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicFlash\start_files and double-click buttons_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicFlash\start_files and double-click buttons_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicFlash/start_files and double-click buttons_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
the behavior.
3. In the Registration grid, verify that the square in the upper left corner is selected as the
registration point, and click OK. The registration point is the point from which the symbol aligns and rotates.
70
With the button that you created still selected, open the Property inspector (Window >
Properties). In the Instance Name text box, type logo_btn.
of the button that you created. The only areas of the button that are clickable (as indicated when the pointer changes to a hand) are the text area and the logo. The white space around the text and logo are not clickable.
3. Select Control > Enable Simple Buttons again to deselect the feature so that you can edit
the button. Next, youll redefine the hit area so that the button area covers the entire grouped area.
2. Double-click the Layer 1 name in the Timeline and rename the layer Hit Area.
71
3. Select the Hit frame (Frame 4) of the Hit Area layer in the BTNLogo Timeline, and press F6
to add a keyframe.
4. In the Tools panel, select the Rectangle tool. The stroke and fill color are unimportant. On the
Stage, draw a rectangle that covers, as closely as possible, the logo and text.
The hit area changes to the shape of the rectangle that you drew.
8. Select Control > Enable Simple Buttons to deselect that feature.
Align buttons
You can align buttons along horizontal and vertical axes using the Align panel.
1. In the Timeline, click the Content layer. 2. Click the Insert Layer button below the Timeline. 3. Double-click the layer name, type Animated Buttons as the new name for the layer, and press
Enter or Return.
4. In the Library panel (Window > Library) select Button 1 and drag it to the lower right edge of
5. In the Instance Name text box in the Property inspector, give the button the instance
name links_btn.
6. Drag Button 2 and Button 3 from the Library panel, placing them to the left of Button 1.
7. Using the Selection tool, drag to select all three buttons. 8. Open the Align panel by selecting Window > Design Panels > Align. Verify that To Stage is not
selected, because you do not want to align the buttons relative to the Stage.
9. In the Align panel, click Align Vertical Center, and then click Distribute Horizontal Center.
selected, then select Button 2. In the Instance Name text box in the Property inspector, enter contact_btn. Select Button 3 and name it sweepstakes_btn.
72
Over keyframe.
Note: You hide layers by clicking the dot under the Eye column next to the layer name so that a red X appears.
3. On the Stage, select the black oval shape for Button 1. Press F8 to make the oval a symbol. 4. In the Convert to Symbol dialog box, name the symbol Button Animation. Select Movie Clip
inspector select a bright shade of red from the Fill Color pop-up menu.
8. In the Timeline, click any frame between Frames 1 and 15. In the Property inspector, select
Shape from the Tween pop-up menu. Drag the playhead from Frames 1 to 15 to see the color change.
category of the Actions toolbox and double-click stop. The stop action lets you specify that the playhead stop when it reaches Frame 15. In the Button Animation Timeline, Frame 15 of the Actions layer now displays a small a, which indicates that an action is attached to that frame.
5. Click Scene 1, above the Stage, to exit symbol-editing mode and return to the main document. 6. Click the options menu control in the upper right of the Actions panel, and select Close Panel
73
8. On the Stage, move the pointer over the button and click the button. 9. Select Control > Enable Simple Buttons to deselect that feature.
3. In the Go to URL dialog box, select _blank in the Open In pop-up menu to open the URL in
a new browser window. In the URL text box, either accept the default setting of http:// www.macromedia.com or enter a different URL. Then click OK.
4. If desired, repeat the steps above, selecting Button 2, then Button 3, to add navigation to those
buttons as well.
5. Click the options menu control in the upper right of the Behavior panel, and select Close Panel
you created.
3. Click the button to see if your web browser opens to the URL that you specified. 4. If you added navigation to the other two buttons, test those buttons as well. 5. When you finish viewing the SWF file, close the SWF file and web browser windows.
74
Summary
Congratulations on learning about buttons. In a few minutes, you were able to accomplish the following tasks:
Create a button from grouped objects Name a button instance View the hit area of a button Change the hit area of a button Align buttons Create animation for a button state Add an action to a button Add navigation to a button
Summary
75
76
Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 provide a variety of text features and options. This lesson introduces you to the three primary types of text you can add to a document. You can add static text for titles, labels, or other text content you want to appear in a document. You can also use input text options to allow viewers to interact with your Flash applicationfor example, to enter their name or other information in a form. The third type of text is dynamic text. You use dynamic text fields to display text that changes based on criteria you specify. For example, you might use a dynamic text field to add values stored in other text fields, such as the sum of two numbers. After taking this lesson, be sure to explore additional text options described in Working with Text in Using Flash. In this lesson, youll add text and text fields to a document as you accomplish the following tasks:
Create an expanding-width text block Create a fixed-width text block Edit text and change font attributes Select device fonts Add an input text field Copy a text field Assign instance names to text fields Create a dynamic text field View ActionScript that links the text field to an external text file Set up and check spelling
77
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicFlash\start_files and double-click text_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicFlash\start_files and double-click text_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicFlash/start_files and double-click text_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
2. To open the start file, in Flash select File > Open. Then do one of the following:
If youre using a Windows 2000 or XP operating system, browse to boot drive\ Documents and Settings\username\Local Settings\Application Data\Macromedia\ Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicFlash\ start_files and double-click text_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
If youre using a Windows 98 operating system, browse to boot drive\Windows\ Application Data\Macromedia\Flash MX 2004\language\ Configuration\HelpPanel\ HowDoI\BasicFlash\start_files and double-click text_start.fla. If youre using a Macintosh operating system, browse to Macintosh HD/Users/username/ Library/Application Support/Macromedia/Flash MX 2004/language/Configuration/ HelpPanel/HowDoI/BasicFlash/start_files and double-click text_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
3. Select File > Save As and save the document with a new name, in the same folder, to preserve
the original start file and to preserve the files link to dependent files.
4. Select Window > Panel Sets > Training Layout to modify your workspace for taking lessons. 5. In the Stage View pop-up menu, in the upper right side of the Timeline, select Show Frame to
78
are selected.
2. In the Tools panel, select the Text tool. 3. In the text Property inspector, set the following options:
In the Text Type pop-up menu, select Static text, if it isnt already selected. For Font, select Arial. For Font Size, enter 13. Click the text color box and select the gray with a hexadecimal value of #666666.
4. In the Timeline, select the Static Text layer. 5. With the Text tool still selected, click the Stage along the left edge of Text 1 guide, and type
Trio ZX2004 Safety Features. By typing with the Text tool selected, you create a one-line text block that expands as you type. An expanding-width one-line static text block has a round handle in the upper right corner.
6. If necessary, align the text above the Text 1 guide by clicking the Selection tool in the Tools
panel and dragging the text that you typed to the guide.
Note: Text 1 guide is on a guide layer, which doesnt appear in your SWF file.
deselect any objects on the Stage or Timeline frames (click in the workspace, away from objects)
2. In the Tools panel, select the Text tool. 3. In the Property inspector, change the text size to 10 points.
79
4. On the Stage, drag your pointer over the area of the Text 2 guide.
An extendable one-line static text block has a round handle in the upper right corner, and a fixed-width static text block has a square handle.
5. Inside the text block that you created, type Want to learn more?
Note: You can drag the square handle for a text block to change its width. Additionally, you can double-click a square handle to convert it into a round expanding handle.
6. If necessary, align the text by clicking the Selection tool in the Tools panel and dragging the text
contact information.
3. In the Tools panel, click the Selection tool. Use the Property inspector to select the bold style. 4. Click the text Fill Color control and choose a different text color, such as another shade of gray.
You will not see a difference in the text if you have the Arial font installed on your computer.
80
Select Input Text in the Text Type pop-up menu Select Arial in the Font pop-up menu. For the font size, enter 8. Click the text color box and select a shade of dark blue. Select the Alias Text button. The Alias Text button renders text so that it appears more readable at small sizes. For input text, this option is supported if the end user has Macromedia Flash Player 7 or later.
Select Single Line in the Line Type pop-up menu, and verify that Show Border Around Text is selected. Single Line displays the text as one line. Show Border Around Text indicates the boundaries of the text field with a visible border.
5. On the Stage, drag the pointer in the area to the right of the First Name text to create an input
text field.
6. If necessary, use the Selection tool to reposition the input text field.
press Alt on your keyboard. Drag a copy of the text field to the right of Last Name.
2. Alt-click the input text field that you just dragged, and then drag the new copy of the field to
eMail Address.
81
eMail_txt in the Instance Name text box. To learn more about the TextField object, see Working with Text in Using ActionScript in Flash.
Select Dynamic Text from the Text Type pop-up menu. For Text Attributes, set Verdana as the text type, with a font size of 6. For Line Type, select Multiline to ensure the text wraps correctly. Click the text color box and select a dark shade of gray. Select Align Left as a paragraph attribute, if it isnt already selected.
4. On the Stage, drag to create a text field in the area between the two horizontal rules.
5. In the Instance Name text box of the Property inspector, name the dynamic text field
newFeatures_txt. The ActionScript in this document loads an external text file, which is in the same folder as your document. The ActionScript is set up to load the text into a field named newFeatures_txt.
82
The dynamic text now has 5-pixel left and right margins within the text field.
In the SWF file window, text from the external text file should appear in the dynamic text field that you created. (If the text does not appear as expected, check that you entered the instance name correctly: newFeatures_txt. Also check that you saved your copy of the practice file in the same folder as the original text_start file.)
2. Type in the input text fields. 3. When you finish testing the file, close the SWF file window.
83
Check spelling
Flash MX 2004 and Flash MX Professional 2004 introduce new features that let you check spelling in most places where text occurs in your document, including text fields, layer names, and ActionScript strings. To check spelling, you first configure the Spelling Setup options, and then run the spell checker.
1. Select Text > Spelling Setup. 2. Verify that Check Text Fields Content is selected, and that youve selected the appropriate
Summary
Congratulations on learning the basic ways in which to add text to your document. In a few minutes, you learned how to accomplish the following tasks:
Create an expanding-width text block Create a fixed-width text block Edit text and change font attributes Select device fonts Add an input text field Copy a text field Assign instance names to text fields Create a dynamic text field View ActionScript that links the text field to an external text file Set up and check spelling
To learn more about the great variety of options you have when adding text to your document, see Working with Text in Using Flash.
84
Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 provide powerful tools for creating animation. Most simple animation in Flash is done using a process known as tweening. Tweening is short for in between and refers to filling in the frames between two keyframes so that a graphic displayed in the first keyframe changes into the graphic displayed in the second keyframe. There are two types of tweening you can create in Flasha motion tween and a shape tween. The main difference between motion tweening and shape tweening is that motion tweening operates on grouped objects or symbols, and shape tweening is used with objects that are not symbols and are ungrouped. In this lesson you will learn how to accomplish the following tasks:
Create an animation using motion tweening Create an animation using shape tweening Copy and paste keyframes in an animation Change the speed of an animation
85
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicFlash\start_files and double-click animation_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicFlash\start_files and double-click animation_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicFlash/start_files and double-click animation_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
Timeline view. You can also use the scroll bar to scroll through the layers.
(Window > Library) to the Stage, positioning it above the tire shadow.
86
4. With the Selection tool still selected, in the TireAnim layer, select Frame 30. Then press F6 to
insert a keyframe.
5. Select Frame 15 and press F6 to add another keyframe. 6. With the playhead still on Frame 15, hold the Shift key to move the tire in a straight line, and
7. In the TireAnim layer, select any frame between Frames 2 and 14. In the Property inspector,
select Motion from the Tween pop-up menu. An arrow appears in the Timeline between the two keyframes.
8. Select any frame between frames 16 and 29. Again, use the Tween pop-up menu in the Property
a keyframe.
87
3. With the playhead on Frame 15, select the Selection tool. Drag the tire shadow slightly up and
to the right.
4. With Frame 15 still selected, select the Eyedropper tool in the Tools panel, and then click the
shadow object.
5. If the Color Mixer is not already open, select Window > Design Panels > Color Mixer to open
6. Click the options menu control in the upper right of the Color Mixer, and select Close Panel
88
4. Select the transformation center point (the small circle near the center of the movie clip) and
drag it to the bottom of the tire. The center point snaps to the lower middle transform handle.
5. On the Stage, drag the upper middle transform handle down to slightly compress the tire shape.
If necessary, drag the tire to align it over the shadow. To view the positioning, drag the playhead over Frames 1 and 2.
6. Save your file.
Note: Always save your document before attempting to manipulate tweens, including copying, cutting, and pasting frames. If you make an error, you can revert to your saved document.
7. Right-click (Windows) or Control-click (Macintosh) Frame 1 of the TireAnim layer and select
The frame rate applies to the entire Flash document, not just to an animation within the document.
89
Change the acceleration and deceleration By default, tweened frames play at a constant speed. With easing, you can create a more realistic rate of acceleration and deceleration. Positive values begin the tween rapidly and decelerate the tween toward the end of the animation. Negative values begin the tween slowly and accelerate the tween toward the end of the animation. Youll now add both positive and negative easing values to your animation.
1. On the TireAnim layer, select any frame between Frames 2 and 14. Then in the Property
inspector, in the Ease text box, type 100. Press Enter or Return.
2. On the same layer, select any frame between Frames 16 and 29. Then in the Ease text box, type
Summary
Congratulations on learning how to animate objects in Flash. In just a few minutes, you learned how to accomplish the following tasks:
Create an animation using motion tweening Create an animation using shape tweening Copy and paste keyframes in an animation Change the speed of an animation
You can also use Timeline effects to quickly add animation effects to text, graphics, images, and symbols. For more information, see Creating Motion in Using Flash. To learn more about Flash, take another lesson.
90
Flash MX Professional 2004 offers a new way, with slide screens, to create presentations. If you can imagine placing media on slide screens, adding nested slides that inherit media from other slides, and using the built-in controls to navigate through the slides at runtime, then youve imagined exactly how easy it is to create a presentation with slide screens. This lesson demonstrates the simplicity of slides as you accomplish the following tasks:
Add content to a presentation slide Add screen navigation to buttons Add and name a slide Select and move slides Add content to a new slide Add transition behaviors to a slide
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\ HelpPanel\ HowDoI\BasicFlash\start_files and double-click presentation_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicFlash\start_files and double-click presentation_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicFlash/start_files and double-click presentation_start.fla.
Note: The BasicFlash\finished_files folder contains completed versions of lesson FLA files, for your reference.
91
the original start file. As you complete this lesson, remember to save your work frequently.
3. Select Window > Panel Sets > Training Layout to configure your workspace.
The Screen Outline pane displays a thumbnail view of each slide in the presentation, and the presentation hierarchy. When you select a screen in the Screen Outline pane, the screen appears in the Document window. When you select multiple screens, the contents of the first screen selected appear in the Document window.
2. In the Screen Outline pane, select the presentation screen.
All slide screen documents contain a presentation screen, which is at the top level of the screen hierarchy. Think of the presentation slide as a master slide: content on the presentation slide can appear in all slides in your document.
Note: You cannot delete or move the presentation screen.
The four slides that appear indented beneath the presentation slide in the pane represent nested, or child, screens, and the presentation slide is the parent.
3. Open the Timeline, if its not already open (Window > Timeline). Select another slide in the
Screen Outline pane to view the Timeline for that screen. Each screen has its own Timeline. The main Timeline for a document with screens, however, is never visible.
92
The Property inspector allows you to change the instance name, which is also the name of the screen as it appears in the Screen Outline pane.
2. Select the actual presentation slide, not the thumbnail.
The Property inspector now displays the same controls youre probably used to when working with the Stage and document properties.
4. Enter forwardBtn in the Instance Name text box. 5. Drag btn, prev to the slide and use the Property inspector to enter 245 in the X text box and
all slides.
Note: Content on a parent screen appears slightly dimmed when you view it on a nested screen.
93
1. On the presentation slide, select the forwardBtn instance. In the Behaviors panel (Window >
Development Panels > Behaviors) click the Add (+) button, and then select Screen > Go to Next Slide from the menu.
2. On the presentation slide, select the backBtn instance. In the Behaviors panel (Window >
Development Panels > Behaviors) click the Add (+) button, and then select Screen > Go to Previous Slide from the menu.
3. Select Control > Test Movie, and click the buttons in the SWF file window that appears, to
ensure your buttons function as expected. When you finish testing your document, close the SWF file window.
A new screen appears in the Screen Outline pane, at the same level as the title slide. The new slide automatically inherits media from the presentation slide.
2. Double-click the new slides name in the Screen Outline pane, and name the slide features.
94
context menu.
3. In the Screen Outline pane, right-click (Windows) or Control-click (Macintosh) the features
slide and select Paste Nested Screen from the context menu. The three slides now appear as children of the features slide.
features_mc.
3. In the Property inspector, enter -275 in the X text box and -130 in the Y text box to place
the instance.
lower left side of the dialog box. Verify that 2 seconds is selected as the duration and that In is selected as the direction, and click OK.
3. In the Behaviors panel, click Reveal in the Event column to open the pop-up menu and select
revealChild. The revealChild option specifies that the behavior will reveal the next child screen.
95
4. To add the Fly behavior, verify that the features slide is still selected. In the Behaviors panel,
click the Add (+) button and select Screen > Transition from the menu.
5. In the Transitions dialog box, select Fly from the list of transitions, and select Out as
the direction.
6. In the Duration text box, enter .5 as the length of time to complete the transition. 7. In the Start Location pop-up menu, select Left Center and watch the transition preview, then
click OK. In the Behaviors panel, revealChild now appears twice. With the Fly behavior, however, you want to hide the child screen.
8. In the Behaviors panel, click the second event in the list, which is the one you just added. In the
the transitions.
Summary
Congratulations on learning how to create a slide presentation with screens. In a few minutes, you learned how to accomplish the following tasks:
Add content to a presentation slide Add screen navigation to buttons Add and name a slide Select and move slides Add content to a new slide Add transition behaviors to a slide
To learn more about using screens, see Working with Screens (Flash Professional Only) in Using Flash.
96
Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 offer numerous ways to engage users with interactivity. Additionally, when you incorporate interactivity, youre not limited to playing each Timeline frame sequentially, which offers greater design and development options. Youll learn some of the ways to implement interactivity in this lesson as you accomplish the following tasks:
Create a new scene Write ActionScript to navigate between scenes Write ActionScript to play an animated movie clip at runtime Use a behavior to play an MP3 file
Note: If you have Macromedia Flash MX Professional 2004, you can use screens to create a document. Screens provide additional navigation options. Slide screens, for example, already include built-in navigation that allows users to move through screens using keyboard arrow keys. For more information about screens, select Help > How Do I > Basic Flash > Create a Presentation with Screens (Flash Professional Only).
97
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicActionScript\start_files and double-click interactivity_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicActionScript\start_files and double-click interactivity_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicActionScript/start_files and double-click interactivity_start.fla.
Note: The BasicActionScript\finished_files folder contains completed versions of lesson FLA files, for your reference.
2. To open your start file, in Flash select File > Open. Then do one of the following:
If youre using a Windows 2000 or XP operating system, browse to boot drive\Documents and Settings\username\Local Settings\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\HowDoI\BasicActionScript\ start_files and double-click interactivity_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
If youre using a Windows 98 operating system, browse to boot drive\Windows\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicActionScript\start_files and double-click interactivity_start.fla. If youre using a Macintosh operating system, browse to Macintosh HD/Users/username/ Library/Application Support/Macromedia/Flash MX 2004/language/Configuration/ HelpPanel/HowDoI/BasicActionScript/start_files and double-click interactivity_start.fla.
Note: The BasicActionScript\finished_files folder contains completed versions of lesson FLA files, for your reference.
the original start file. As you complete this lesson, remember to save your work frequently.
4. Select Window > Panel Sets > Training Layout to configure your workspace. 5. In the Stage View pop-up menu, in the upper right of the Timeline, select Show Frame to view
98
(Window > Properties), type goScene_btn in the Instance Name text box to name the instance of the symbol.
2. Select the middle button and use the Property inspector to give the button an instance name of
attachMovie_btn.
3. Select the far right button and use the Property inspector to give the button an instance name
of playSound_btn.
Add a scene
You can use scenes in Flash to organize your document into discrete sections that can contain content exclusive of other scenes. Youll create and add content to a new scene.
1. Select Insert > Scene.
You can no longer see Scene 1, and Scene 2 now appears above the Stage. The Stage is empty.
2. From the Library panel (Window > Library), drag the Animation movie clip to the Stage. With
the movie clip selected, use the Property inspector to give the instance an x coordinate of 200 and a y coordinate of 15. Press Enter or Return. The movie clip moves to the designated Stage coordinates.
3. Use the Property inspector to give the Animation movie clip an instance name of
animation_mc.
4. Rename Layer 1 Animation. Create a new layer and name it Buttons. Drag an instance of the
BTNback symbol to the Stage, and place it anywhere to the right of the movie clip.
5. Use the Property inspector to give the button an instance name of back_btn.
99
Development Panels > Actions), type the following comment followed by the script that stops the playhead on the frame:
// stops the playhead at Frame 1 stop();
Press Enter or Return twice and type the following comment, then write the function that
takes users to Scene 2 upon release of the goScene_btn instance:
// This script takes the user to Scene 2 when goScene_btn is released goScene_btn.onRelease = function (){ gotoAndStop("Scene 2", 1); };
In the script that you just typed, you used the onRelease() method for the button object. The gotoAndStop function is a Timeline control function that lets you specify the scene and frame number. In this case, you specified Frame 1.
The only differences between this function and the function in Scene 1 are the name of the button and the name of the scene.
3. In the Scene panel, select Scene 1.
100
Movie clips that are exported for use with ActionScript load, by default, before the first frame of the SWF file that contains them. This can create a delay before the first frame plays. When you assign a linkage identifier to an element, you can specify that the movie clip load on the first frame to avoid playback delays. Use the attachMovie() method to play a movie clip Youll now use the attachMovie() method to load the movie clip and provide the symbol with an instance name. Since the instance of the symbol does not exist on the Stage, youll create the instance name programmatically.
1. In the Timeline, select Frame 1 of the Actions layer for Scene 1. 2. In the Script pane of the Actions panel, place the insertion point at the end of your last line of
code. Press Enter or Return, and then type the following to add a comment and create a new function:
//function plays trio_mc when attachMovie_btn instance is released. attachMovie_btn.onRelease = function(){
Next, youll specify what the function does: it plays the movie clip on the root Timeline, which is the main Timeline. In your script, youll refer to the movie clip by the linkage identifier name in the Linkage Properties dialog box (MCTrio). Additionally, even though you didnt place an instance of the MCTrio symbol on the Stage, youll use ActionScript to create an instance name for the symbol. The instance name that youll specify is trio_mc.
3. With the insertion point at the end of the last line of script, press Enter or Return. Then type
the following:
_root.attachMovie("MCTrio", "trio_mc", 1);
The number 1 in the script that you just typed refers to the depth on the layer in which to play the movie clip. Every movie clip instance has its own z axis (depth) that determines the stacking order of a movie clip within its parent SWF file or movie clip. When you create a new movie clip at runtime using the attachMovie() method, you always specify a depth for the new clip as a method parameter.
101
Note: For more information about the attachMovie() method, see attachMovie() in the Flash ActionScript Language Reference. Additionally, you can use the Flash ActionScript Language Reference for information about ActionScript that allows you to manage depth; getNextHighestDepth(), getDepth(), getInstanceAtDepth() are methods of the MovieClip class. The DepthManager class allows you to manage the relative depth assignments of a movie clip.
Specify movie clip Stage coordinates In addition to the z axis for the movie clip, you must specify the x and y coordinates to place the movie clip within the Stage area at runtime.
Press Enter or Return after the last line in the Script pane and type the following:
trio_mc._x = 275; trio_mc._y = 200; };
Unload the movie clip After the movie clip plays, you need a way to remove the movie clip from the Stage when the user goes to Scene 2. You can modify your script for the goScene_btn to unload the movie clip.
1. In the Timeline, select Frame 1 of the Actions layer. Then click at the end of the following line
of script in the Script pane, within the function that takes the user to Scene 2, to place the insertion point:
gotoAndStop("Scene 2", 1);
2. Press Enter or Return and type the following script, which unloads the movie clip when the
function runs, so that the movie clip does not continue to play when the user goes to Scene 2:
unloadMovie("trio_mc");
102
click OK.
Summary
Congratulations on learning how to create an interactive document. In a few minutes, you learned how to accomplish the following tasks:
Create a new scene Write ActionScript to navigate between scenes Write ActionScript to play an animated movie clip at runtime Use a behavior to play an MP3 file
To learn more about ActionScript, take another lesson in the Basic ActionScript series.
Summary
103
104
You can create a form with conditional logic that allows the SWF file to respond in different ways, depending on user interaction, and send the form data from the SWF file to an external source. In this lesson, you will create a simple form as you complete the following tasks:
Add an input text field to collect form data Create a button symbol Add a stop() action Write a script that validates the form with conditional logic Pass data out of a SWF file Write a function
Before taking this lesson, you should be familiar with writing functions and variables; to learn about these, select Help > How Do I > Quick Tasks > Create an Application.
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\ Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicActionScript\start_files and double-click simpleForm_start.fla.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
On Windows 98, browse to boot drive\Windows\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicActionScript\start_files and double-click simpleForm_start.fla. On Macintosh, browse to Macintosh HD/Users/Shared/Application Support/Macromedia/ Flash MX 2004/language/Configuration/HelpPanel/HowDoI/BasicActionScript/start_files and double-click simpleForm_start.fla.
105
Note: The BasicActionScript\finished_files folder contains completed versions of lesson FLA files, for your reference.
2. Select File > Save As and save the document with a new name, in the same folder, to preserve
Timeline view.
Select Input Text from the Text Type pop-up menu. Select _sans from the Font pop-up menu. Enter 10 in the Font Size text box. Click the text color box and select a shade of dark blue. Verify that Align Left is selected. Verify that Single Line is selected in the Line Type pop-up menu.
4. In the Timeline, select Frame 1 of the Input Text layer. 5. On the Stage, drag the Text tool to create an input text field to the right of the http:// text.
6. If necessary, use the Selection tool to drag the text field or use the arrows keys to adjust
the position.
7. With the input text field still selected, in the Property inspector, type url_txt in the Instance
Name text box. Youll refer to the instance name later when you add ActionScript.
106
Chapter 14: Create a Form with Conditional Logic and Send Data
2. Drag the button or use the arrows keys to adjust the position, if necessary. 3. In the Property inspector, type submit_btn in the Instance Name text box.
the selected layer and select Insert Blank Keyframe from the context menu.
3. From the Library panel, drag the Dialog Box-error movie clip to the center of the Stage.
4. In the Timeline, select Frame 5 of the Buttons layer. Drag the Try Again Button symbol from
the Library panel to the Stage, placing the button below the error message text.
5. With the button still selected, in the Property inspector, enter tryAgain_btn in the Instance
107
(Macintosh) the selected frame and select Insert Blank Keyframe from the context menu.
2. From the Library panel, drag the Dialog Box-confirm movie clip to the center of the Stage. 3. Close the Library panel.
4. Click in the Script pane of the Actions panel, and type the following comment: //Stops the
playhead at Frame 1.
108
Chapter 14: Create a Form with Conditional Logic and Send Data
3. Add a keyframe to Frame 10 of the Actions layer. In the Property inspector, type confirm in the
2. Type the following comment: //Adds conditional logic for the Submit button that
validates user input.
3. In the Actions panel, click the Insert a Target Path button, located at the top of the panel. 4. In the Insert Target Path dialog box, verify that Relative is selected. Click submit_btn on the
Return.
109
11. Type gotoAndStop("confirm") in the Script pane. Press Enter or Return, and type }, then
press Enter or Return again and type };. Your script should appear as follows:
//Stops the playhead at frame 1 stop(); //Adds conditional logic for the Submit button that validates user input this.submit_btn.onRelease = function(){ if (url_txt.text == null || url_txt.text ==){ gotoAndStop("error"); } else { gotoAndStop("confirm") } };
2. Then in the Actions toolbox, select Global Functions > Browser/Network and double-click
getURL.
3. With the insertion point within the getURL() parentheses, type "http://"+url_txt.text to
specify the data that should pass from the SWF file. (Do not leave spaces in the code.) Your script should look like the following:
stop(); this.submit_btn.onRelease = function(){ if (url_txt.text == null || url_txt.text ==){ gotoAndStop("Error"); } else { getUrl ("http://"+url_txt.text); gotoAndStop("Confirm") } };
110
Chapter 14: Create a Form with Conditional Logic and Send Data
3. Type tryAgain_btn.onRelease = function(){, then press Enter or Return. 4. Type gotoAndStop(1);, then press Enter or Return and type } to complete the script.
Click the Submit button. Your default browser opens the web page.
Summary
Congratulations on learning how to write a script with conditional logic and send data. In a few minutes, you learned how to complete the following tasks:
Add an input text field to a document Create a button symbol Add a stop() action Write a script that validates the form with conditional logic Pass data out of a SWF file Write a function
Summary
111
112
Chapter 14: Create a Form with Conditional Logic and Send Data
Classes are the blueprint for objects in Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004. All objects in Flash have an underlying class; for example, all movie clips have a method called getURL, and getURL is defined in the class definition for a movie clip. Flash contains many predefined classes, such as the MovieClip class, the Array class, the Color class, and the CheckBox class. In this lesson, youll learn about creating and modifying classes. Specifically, youll learn how to accomplish the following tasks:
Create objects from existing classes Create a custom class Use datatyping with custom classes Extend an existing class
Note: This lesson is designed for Flash developers who are familiar with basic Flash and ActionScript concepts.
handson1.fla, handson2.fla, handson3.fla, Product.as, and Drag.as, which are examples of the files that youll create in this lesson:
On Windows 2000 or XP, browse to boot drive\Documents and Settings\All Users\Application Data\Macromedia\Flash MX 2004\language\Configuration\HelpPanel\ HowDoI\BasicActionScript\finished_files.
Note: If the Application Data folder is hidden, youll need to change your Windows Explorer settings to see the folder.
113
2. Select Window > Panel Sets > Training Layout to configure your workspace.
You should see a number in the Output panel that represents the month. The getMonth() method displays the current month. The getMonth() method is zeroindexed, meaning the numbering begins at zero rather than one, so the number displayed is one less than what you would expect.
8. Close the Output panel and the SWF file window.
114
Chapter 15: Work with Objects and Classes Using ActionScript 2.0
Modify your script Youll modify your script to compensate for the zero indexing.
1. Add +1 to the value when you create currentMonth, and test your document to be sure the
expected month number appears. That line of script should read as follows:
var currentMonth:Number = myDate.getMonth()+1;
3. Below the trace statement, set the autoSize property of your text box to true:
currentDate_txt.autoSize = true;
4. Use the text property of your text box to display todays date in the form Today is mm/dd/yyyy.
Use the currentMonth variable you have already created, plus the getDate() and getFullYear() methods of the Date object:
currentDate_txt.text="Today is "+currentMonth+"/"+ myDate.getDate() + "/ "+myDate.getFullYear();
6. Save and test the document. The current date should appear in the SWF file window.
Note: An example finished file of the document you just created, named handson1.fla, is located in your finished files folder. For the path, see Set up your workspace on page 113.
115
In order to properly define a class in ActionScript 2.0, you must surround all classes by the class keyword, and you must declare all variables in the constructor outside of the constructor. Following is an example:
Note: The following ActionScript is an example only. You should not enter the script in your lesson FLA file. class Product { //variable declaration var id:Number var productName:String var price:Number //constructor function Product (id:Number, prodName:Name, price:Number) { this.id = id; this.prodName = prodName; this.price = price; } }
To create objects from this class, you could now use the following code:
Note: The following ActionScript is an example only. You should not enter the script in your lesson FLA file. var cliplessPedal:Product=new Product(1, "Clipless Pedal", 11); var monkeyBar:Product=new Product(2, "Monkey Bar", 10);
However, in ActionScript 2.0, variables that are part of a class structure should not be accessed directly. You should write methods within the class that will access these variables directly. There should be different methods that get and set properties (known as getter and setter methods). You must indicate the data type for both a methods return value and any parameters that are passed to the method when it is called. Specify the data type for method return values You must indicate data types for values returned by methods after the method name and list of parameters, as in the following example:
Note: The following ActionScript is an example only. You should not enter the script in your lesson FLA file. public function getProductName() :String { return name; }
If no value is returned (for example, a property is being set), the data type is Void:
public function setProductName(productName:String) :Void { this.productName=productName; }
116
Chapter 15: Work with Objects and Classes Using ActionScript 2.0
Build a custom class Youll now build a new Product class with getter and setter methods and create an object from the Product class.
1. Create an ActionScript file by doing one of the following:
If youre using Flash MX 2004 Professional, select File > New > ActionScript File (Not Flash Document). Save the document with the name Product. If youre using Flash MX 2004, open a text editor, such as Notepad. Save the file with the name Product.as. (Remember to give the file the AS extension, to create an ActionScript file.)
2. Create a constructor for a Product class by creating a function called Product that takes the
3. In the constructor function, set the properties of the Product class equal to the setter methods
4. Wrap the constructor function around the class keyword. Be sure to declare each variable used
in the class:
class { var var var Product id:Number; prodName:String; description:String
5. Define getter and setter methods for each property of the class, as in the following example. Be
sure to specify Void as the return type for the setter methods, and indicate the data type returned for the getter methods.
class Product { var id:Number; var prodName:String; var description:String function Product (id:Number, prodName:String, description:String) { setID(id); setProdName(prodName); setDescription(description);
117
} public function setID (id:Number) :Void { this.id = id; } public function setProdName (prodName:String) :Void { this.prodName = prodName; } public function setDescription (description:String) { this.description = description; } public function getID () :Number { return id; } public function getProdName () :String { return prodName } public function getDescription () :String { return description; } } :Void
from the Product class using the data shown in the following table (the ActionScript that youll create appears after the table).
Instance name
pedals
Data
id prodName description 0 Clipless Pedals Excellent cleat engagement 1 ATB Available in comfort and aero design
handleBars
id prodName description
118
Chapter 15: Work with Objects and Classes Using ActionScript 2.0
5. Save and test the document. You should see the description of pedals in the Output panel.
Note: An example finished file of the document you just created, named handson2.fla, is located in your finished files folder. For the path, see Set up your workspace on page 113.
The Drag class now inherits all properties and methods from the existing MovieClip class, and you can use MovieClip properties and methods anywhere within the class definition, as in the following example:
Note: The following ActionScript is an example only. You should not enter the script in your lesson FLA file. class Drag extends MovieClip { // constructor function Drag () { onPress=doDrag; onRelease=doDrop; } private function doDrag():Void { this.startDrag(); } private function doDrop():Void { this.stopDrag(); } } Note: The Convert to Symbol dialog box now offers a class field in which you can associate visual objects (such as movie clip) with any class that you define in ActionScript 2.0.
119
(Windows) or Control-click (Macintosh) the shape and select Convert to Symbol from the context menu.
3. In the Convert to Symbol dialog box, select Movie Clip as the behavior, and click Advanced.
This associates the movie clip with the Drag class that youll create.
6. Using the Property inspector, assign the movie clip an instance name. Then save the FLA file.
Note: An example finished file of the document you just created, named handson3.fla, is located in your finished files folder. For the path, see Set up your workspace on page 113.
If youre using Flash MX 2004 Professional, select File > New > ActionScript File (Not Flash Document). Save the document with the name Drag, in the same location where you saved Shape.fla. If youre using Flash MX 2004, open a text editor, such as Notepad. Save the file with the name Drag.as, in the same location where you saved Shape.fla.
8. In the ActionScript file that you just created, create a new class and constructor called Drag:
class Drag extends MovieClip { function Drag () { onPress=doDrag; onRelease=doDrop; } }
120
Chapter 15: Work with Objects and Classes Using ActionScript 2.0
9. Define private methods in the class that use the existing movie clip methods, startDrag() and
stopDrag(): class Drag extends MovieClip { function Drag() { onPress=doDrag; onRelease=doDrop; } private function doDrag():Void { this.startDrag(); } private function doDrop():Void { this.stopDrag() } }
10. Save the ActionScript file. 11. Test the Shape.fla document. You should be able to drag the movie clip.
Note: An example of the ActionScript file you just created, named Drag.as, is located in your finished files folder. For the path, see Set up your workspace on page 113.
Summary
Congratulations on learning how to work with objects and classes in ActionScript 2.0. In a few minutes, you learned how to accomplish the following tasks:
Create and use objects from existing classes Create a custom class Create a property within a custom class Create a method within a custom class Extend an existing class and take advantage of inheritance
Summary
121
122
Chapter 15: Work with Objects and Classes Using ActionScript 2.0