Tài liệu Using ActionScript in Flash-P1 doc

100 372 0
Tài liệu Using ActionScript in Flash-P1 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Using ActionScript in 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: Linda Adler, Mary Ferguson, Mary Kraemer, Noreen Maher, Antonio Padial, Lisa Stanziano, Anne Szabla Production Management: Patrice O’Neill 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 3 CONTENTS INTRODUCTION: Getting Started with ActionScript . . . . . . . . . . . . . . . . . . . . . . . 7 Intended audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Using the documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Typographical conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Terms used in this document. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Additional resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 CHAPTER 1: What’s New in Flash MX 2004 ActionScript . . . . . . . . . . . . . . . . . . 11 Updating Flash XML files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 New and changed language elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 New security model and legacy SWF files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Porting existing scripts to Flash Player 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 ActionScript editor changes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Debugging changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 New object-oriented programming model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 CHAPTER 2: ActionScript Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Differences between ActionScript and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . 24 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 About data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Assigning data types to elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 About variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Using operators to manipulate values in expressions . . . . . . . . . . . . . . . . . . . . . . . 49 Specifying an object’s path. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Using condition statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Using built-in functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Creating functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 CHAPTER 3: Using Best Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Working with FLA files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 General coding conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 ActionScript coding standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Using classes and ActionScript 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 4 Contents Behaviors conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Screens conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Video conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Performance and Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Guidelines for Flash applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Projects and version control guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Guidelines for accessibility in Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Advertising with Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 CHAPTER 4: Writing and Debugging Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Controlling when ActionScript runs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Using the Actions panel and Script window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Using the ActionScript editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Unicode support for ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Debugging your scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Using the Output panel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Updating Flash Player for testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 CHAPTER 5: Handling Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Using event handler methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Using event listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Using button and movie clip event handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Broadcasting events from component instances . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Creating movie clips with button states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Event handler scope. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Scope of the this keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 CHAPTER 6: Creating Interaction with ActionScript . . . . . . . . . . . . . . . . . . . . . 179 About events and interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Controlling SWF file playback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Creating interactivity and visual effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Deconstructing a sample script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 CHAPTER 7: Using the Built-In Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 About classes and instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 Overview of built-in classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 CHAPTER 8: Working with Movie Clips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 About controlling movie clips with ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . 205 Calling multiple methods on a single movie clip . . . . . . . . . . . . . . . . . . . . . . . . . 206 Loading and unloading additional SWF files. . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Specifying a root Timeline for loaded SWF files . . . . . . . . . . . . . . . . . . . . . . . . . 208 Loading JPEG files into movie clips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Changing movie clip position and appearance. . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Dragging movie clips. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Creating movie clips at runtime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Contents 5 Adding parameters to dynamically created movie clips . . . . . . . . . . . . . . . . . . . . 213 Managing movie clip depths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Drawing shapes with ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Using movie clips as masks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 About masking device fonts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Handling movie clip events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Assigning a class to a movie clip symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Initializing class properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 CHAPTER 9: Working with Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Using the TextField class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Creating text fields at runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Using the TextFormat class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 Formatting text with Cascading Style Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Using HTML-formatted text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 Creating scrolling text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 CHAPTER 10: Creating Custom Classes with ActionScript 2.0 . . . . . . . . . . . . . 247 Principles of object-oriented programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 Using classes: a simple example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Creating and using classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Creating dynamic classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 Using packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 Creating and using interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Instance and class members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 Implicit getter/setter methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Understanding the classpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 Importing classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 Compiling and exporting classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Excluding classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 CHAPTER 11: Working with External Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 Sending and loading variables to and from a remote source. . . . . . . . . . . . . . . . . 275 Sending messages to and from Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Flash Player security features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 CHAPTER 12: Working with External Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 Overview of loading external media. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 Loading external SWF and JPEG files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Loading external MP3 files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Reading ID3 tags in MP3 files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 Playing back external FLV files dynamically . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Preloading external media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 6 Contents APPENDIX A: Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 APPENDIX B: Deprecated Flash 4 operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 APPENDIX C: Keyboard Keys and Key Code Values . . . . . . . . . . . . . . . . . . . . . 313 Keys on the numeric keypad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Function keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Other keys. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 APPENDIX D: Writing Scripts for Earlier Versions of Flash Player . . . . . . . . . . . 319 About targeting older versions of Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 Using Flash MX 2004 to create content for Flash Player 4. . . . . . . . . . . . . . . . . . 320 APPENDIX E: Object-Oriented Programming with ActionScript 1 . . . . . . . . . . . 323 About ActionScript 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 7 INTRODUCTION Getting Started with ActionScript Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 are the professional standard authoring tools for producing high-impact web experiences. ActionScript is the language you use to add interactivity to a Flash applications, whether your applications are simple animated movies or more complex rich Internet applications. You don’t have to use ActionScript to use Flash, but if you want to provide basic or complex user interactivity, work with objects other than those built into Flash (such as buttons and movie clips), or otherwise turn a SWF file into a more robust user experience, you’ll probably want to use ActionScript. Intended audience This manual assumes that you have already installed Flash MX 2004 or Flash MX Professional 2004 and know how to use it. You should know how to place objects on the Stage and manipulate them in the Flash authoring environment. If you have written programs before, ActionScript will seem familiar. But if you’re new to programming, ActionScript isn’t hard to learn. It’s easy to start with simple commands and build more complexity as you progress. System requirements ActionScript does not have any system requirements in addition to Flash MX 2004 or Flash MX Professional 2004. To use ActionScript 2.0, you must use Flash MX 2004. The documentation assumes that you are using the default publishing settings for your Flash files: Flash Player 7 and ActionScript 2.0. If you change either of these settings, explanations and code samples shown in the documentation may not work correctly. If you develop applications for earlier versions of Flash Player, see “Porting existing scripts to Flash Player 7” on page 13 or Appendix D, “Writing Scripts for Earlier Versions of Flash Player,” on page 319. Using the documentation This manual provides an overview of ActionScript syntax, information on how to use ActionScript when working with different types of objects, and details on the syntax and usage of every language element. The following list summarizes the contents of this manual. 8 Introduction: Getting Started with ActionScript • Chapter 1, “What’s New in Flash MX 2004 ActionScript,” on page 11 describes features that are new in ActionScript, changes to the compiler and debugger, and the new programming model for the ActionScript 2.0 language. • Chapter 2, “ActionScript Basics,” on page 23 describes the terminology and basic concepts used in the rest of the manual. • Chapter 3, “Using Best Practices,” on page 65 helps explain the best practices for using Flash and writing ActionScript. • Chapter 4, “Writing and Debugging Scripts,” on page 139 describes the ActionScript editor and debugger within Flash that makes it easier to write code. • Chapter 5, “Handling Events,” on page 167 discusses a few different ways to handle events: event handler methods, event listeners, and button and movie clip event handlers. • Chapter 6, “Creating Interaction with ActionScript,” on page 179 describes some simple ways in which you can create more interactive applications, including controlling when SWF files play, creating custom pointers, and creating sound controls. • Chapter 7, “Using the Built-In Classes,” on page 197 lists the built-in classes in ActionScript and provides a brief overview of how you use them to access powerful features in ActionScript. • Chapter 8, “Working with Movie Clips,” on page 205 describes movie clips and the ActionScript you can use to control them. • Chapter 9, “Working with Text,” on page 221 describes the different ways you can control text in Flash and include information on text formatting. • Chapter 10, “Creating Custom Classes with ActionScript 2.0,” on page 247 describes how to create custom classes and objects for manipulating data in your applications. • Chapter 11, “Working with External Data,” on page 275 describes how to process data from external sources using server- or client-side scripts in your applications. • Chapter 12, “Working with External Media,” on page 295 describes how to import external media files such as JPEG, MP3, and other SWF files in your Flash applications. • Appendix A, “Error Messages,” on page 305 contains a list of error messages that the Flash compiler can generate. • Appendix B, “Deprecated Flash 4 operators,” on page 311 lists all the ActionScript operators and their associativity. • Appendix C, “Keyboard Keys and Key Code Values,” on page 313 lists all the keys on a standard keyboard and the corresponding ASCII key code values that are used to identify the keys in ActionScript. • Appendix D, “Writing Scripts for Earlier Versions of Flash Player,” on page 319 provides guidelines to help you write scripts that are syntactically correct for the player version you are targeting. • Appendix E, “Object-Oriented Programming with ActionScript 1” provides information on using the ActionScript 1 object model to write scripts. This manual explains how to use the ActionScript language. For information on the language elements themselves, see ActionScript Language Reference Help. Additional resources 9 Before writing your own scripts, you should complete the lessons “Write Scripts with ActionScript” and “Create a Form with Conditional Logic and Send Data,” which provide a hands-on introduction to working with ActionScript. To find these lessons, select Help > How Do I > Quick Tasks. When you find information about a certain command you want to use, you can look up its entry in ActionScript Language Reference Help. When you find information about a certain command you want to use, you can look up its entry in Flash ActionScript Language Reference. Typographical conventions The following typographical conventions are used in this manual: • Code font indicates ActionScript code. • Code font italic indicates an element, such as an ActionScript parameter or object name, that you replace with your own text when writing a script. Terms used in this document The following terms are used in this manual: • You refers to the developer who is writing a script or application. • The user refers to the person who is running your scripts and applications. • Compile time is the time at which you publish, export, test, or debug your document. • Runtime is the time at which your script is running in Flash Player. ActionScript terms such as method and object are defined in Chapter 2, “ActionScript Basics,” on page 23. Additional resources Specific documentation about Flash and related products is available separately. • For information about the elements that comprise the ActionScript language, see ActionScript Language Reference Help. • For information about working in the Flash authoring environment, see Using Flash Help. • For information about working with components, see Using Components Help. • For information about creating communication applications with Flash Communication Server, see Developing Communications Applications and Managing Flash Communication Server. • For information about accessing web services with Flash applications, see Using Flash Remoting. You can find application FLA files that use common Flash functionality installed with Flash. These applications were designed to introduce new Flash developers to the capabilities of Flash applications as well as show advanced developers how Flash features work in context. On Windows, you can find the applications in \Program Files\Macromedia\Flash MX 2004\ Examples. On the Macintosh, you can find the applications in HD/Applications/Macromedia Flash MX 2004/Examples. 10 Introduction: Getting Started with ActionScript The Macromedia DevNet website (www.macromedia.com/devnet) is updated regularly with the latest information on Flash, plus advice from expert users, advanced topics, examples, tips, and other updates. Check the website often for the latest news on Flash and how to get the most out of the program. The Macromedia Flash Support Center (www.macromedia.com/support/flash) provides TechNotes, documentation updates, and links to additional resources in the Flash community. [...]... LocalConnection.allowInsecureDomain in the called file, using exact domain-name matching, as shown in the code examples earlier in this section This statement is required even if the calling and called SWF files are in same domain 18 Chapter 1: What’s New in Flash MX 2004 ActionScript • If the called file is published for Flash Player 6 or earlier, and both the calling and called files are in same domain (for example, a file in. .. not in the same domain, you can do one of two things You can either port the called file to Flash Player 6 and add or change a System.security.allowDomain statement, using exact domain-name matching, as shown in the code examples earlier in this section, or you can port the called file to Flash Player 7, and include a System.security.allowInsecureDomain statement in the called file, using exact domain-name... Single-click breakpoints To add a debugging breakpoint before a line of code in the Debugger panel or the Script pane on the Actions panel, you can click in the left margin In previous versions of Flash, clicking in the left margin selected a line of code The new way to select a line of code is to Control-click (Windows) or Command-click (Macintosh) Normal and expert modes no longer in Actions panel In previous... single class defined in each script; that is, classes and interfaces cannot be defined in the Actions panel • You can import individual class files implicitly (by storing them in a location specified by global or document-specific search paths and then using them in a script) or explicitly (by using the import command); you can import packages (collections of class files in a directory) by using wildcards... my_lc.allowInsecureDomain = function(sendingDomain) { return(sendingDomain=="www.someSite.com" || sendingDomain=="www.someOtherSite.com"); } You might also have to add statements such as these to your files if you aren’t currently using them A modification might be necessary even if both files are in same domain (for example, a file in http://www.domain.com is calling a file in https://www.domain.com) To summarize,... scorePlayer2_mc The following code sets a variable called score inside each movie clip instance by using instance names: this.scorePlayer1_mc.score = 0; this.scorePlayer2_mc.score = 0; You can use strict data typing when creating instances so that code hints (see Using code hints” on page 147) appear as you type your code For more information, see “Strictly typing objects to trigger code hints” on page 145... System.security.allowDomain("someSite.com"); my_lc.allowDomain = function(sendingDomain) { return(sendingDomain=="someSite.com"); } // Corresponding commands to allow access by SWF files // that are published for Flash Player 7 System.security.allowDomain("www.someSite.com", "store.someSite.com"); my_lc.allowDomain = function(sendingDomain) { return(sendingDomain=="www.someSite.com" || sendingDomain=="store.someSite.com");... more information on using ActionScript 2.0 to write object-oriented programs in Flash, see Chapter 10, “Creating Custom Classes with ActionScript 2.0,” on page 247 Although using ActionScript 2.0 is recommended, you can continue to use ActionScript 1 syntax, especially if you are doing more traditional Flash work such as simple animation that doesn’t require user interaction 22 Chapter 1: What’s New in. .. examples earlier in this section • If the called file is published for Flash Player 6 and you want to port the called file to Flash Player 7, include System.security.allowInsecureDomain or LocalConnection.allowInsecureDomain in the called file, using exact domain-name matching, as shown in the code examples earlier in this section This statement is required even if both files are in same domain • If the... defined in Flash ActionScript Language Reference Variables containing primitive data types behave differently in certain situations than those containing reference types (See Using variables in a program” on page 47.) There are also two special data types: null and undefined When you debug scripts, you might need to determine the data type of an expression or variable to understand why it is behaving . 7, include System.security.allowInsecureDomain or LocalConnection.allowInsecureDomain in the called file, using exact domain-name matching, as shown in. play, creating custom pointers, and creating sound controls. • Chapter 7, Using the Built -In Classes,” on page 197 lists the built -in classes in ActionScript

Ngày đăng: 24/12/2013, 01:17

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan