Detailed instructions for use are in the User's Guide.
Flex ActionScript Language Reference
Trademarks ActiveEdit, ActiveTest, Add Life to the Web, Afterburner, Aftershock, Andromedia, Allaire, Animation PowerPack, Aria, Attain, Authorware, Authorware Star, Backstage, Blue Sky Software, Blue Sky, Breeze, Bright Tiger, Clustercats, ColdFusion, Contents Tab Composer, Contribute, Design In Motion, Director, Dream Templates, Dreamweaver, Drumbeat 2000, EDJE, EJIPT, Extreme 3D, Fireworks, Flash, FlashHelp, Flash Lite, FlashPaper, Flex, Flex Builder, Fontographer, FreeHand, Generator, Help To Source, HomeSite, Hotspot Studio, HTML Help Studio, JFusion, JRun, Kawa, Know Your Site, Knowledge Objects, Knowledge Stream, Knowledge Track, LikeMinds, Lingo, Live Effects, MacRecorder Logo and Design, Macromedia, Macromedia Action!, Macromedia Central, 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!, RoboDemo, RoboEngine JFusion, RoboHelp, RoboHelp Office, RoboInfo, RoboInsight, RoboPDF, 1-Step RoboPDF, RoboFlash, RoboLinker, RoboScreenCapture, ReSize, Roundtrip, Roundtrip HTML, Shockwave, Sitespring, Smart Publishing Wizard, Software Video Camera, SoundEdit, Titlemaker, UltraDev, Web Design 101, what the web can be, WinHelp, WinHelp 2000, WinHelp BugHunter, WinHelp Find+, WinHelp Graphics Locator, WinHelp Hyperviewer, WinHelp Inspector, 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. Opera ® browser Copyright © 1995-2002 Opera Software ASA and its suppliers. All rights reserved. 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. Part Number ZFE15M200 Acknowledgments Project Management: Barbara Herbert, Stephen Gilson Writing: Jody Bleyle, Mary Burger, Kim Diezel, Stephen Gilson, Stephanie Gowin, Dan Harris, Barbara Herbert, Matt Horn, Barbara Nelson, Shirley Ong, Michael Peterson, Tim Statler 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: November 2004 Macromedia, Inc. 600 Townsend St. San Francisco, CA 94103
CONTENTS
INTRODUCTION: Getting Started with ActionScript
....................... 5 5 5 6 6 6
Intended audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Typographical conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Terms used in this document. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Additional resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PART I: Welcome to ActionScript
CHAPTER 1: ActionScript Basics
...................................... 9 10 10 11 13 18 23 27 31 39 41 41
Differences between ActionScript and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . Unicode support for ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assigning data types to elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using operators to manipulate values in expressions . . . . . . . . . . . . . . . . . . . . . . . Using condition statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using built-in functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CHAPTER 2: Creating Custom Classes with ActionScript 2.0 . . . .
. . . . . . . . . . . 45
Principles of object-oriented programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Using classes: a simple example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Creating and using classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Creating dynamic classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Using packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Creating and using interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Instance and class members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Implicit getter/setter methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Understanding the classpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Importing classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3
CHAPTER 3: Working with External Data.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Sending and loading variables to and from a remote source . . . . . . . . . . . . . . . . . . 67 Sending messages to and from Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
PART II: Reference
CHAPTER 4: About the ActionScript Language Reference . .
. . . . . . . . . . . . . . . 77
Sample entry for most ActionScript elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Sample entry for classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
CHAPTER 5: ActionScript Core Language Elements. CHAPTER 6: ActionScript Core Classes. CHAPTER 7: ActionScript for Flash
. . . . . . . . . . . . . . . . . . . . . 80
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490 . . . . . . . . . . . . . . . . . . . . . . . . . . 809 . . . . . . . . . . . . . . . . . . . . 811
APPENDIX A: Deprecated Flash 4 operators .
APPENDIX B: Keyboard Keys and Key Code Values .
Letters A to Z and standard numbers 0 to 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 811 Keys on the numeric keypad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813 Function keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813 Other keys. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814
INDEX
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 817 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823
INDEX OF LANGUAGE ELEMENTS.
4
Contents
INTRODUCTION Getting Started with ActionScript
Macromedia Flex developers can use ActionScript to extend the functionality of their Flex applications. ActionScript is an ECMAScript-based language that provides support for objectoriented development. You are not required to use ActionScript to use Flex, but it provides flow control and object manipulation features that are not available in strict MXML.
Intended audience
This manual assumes that you already installed Macromedia Flex and know how to use it. 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.
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.
· Chapter 1, "ActionScript Basics," on page 9 describes the terminology and basic concepts used
in the rest of the manual.
· Chapter 2, "Creating Custom Classes with ActionScript 2.0," on page 45 describes how to
create custom classes and objects for manipulating data in your applications.
· Chapter 3, "Working with External Data," on page 67 describes how to process data from
external sources using server- or client-side scripts in your applications.
· Chapter 4, "About the ActionScript Language Reference," on page 77 provides an overview of
the second part of the manual, which describes the elements that comprise the ActionScript language.
· Chapter 5, "ActionScript Core Language Elements," on page 80 explains all of the elements of
the ActionScript language that are not related to a particular class or to a particular Macromedia product.
· Chapter 6, "ActionScript Core Classes," on page 232 documents all of the classes of the
ActionScript language that are not related to a particular Macromedia product.
5
· Chapter 7, "ActionScript for Flash," on page 490 describe functions, properties, and classes of
Macromedia Flash Player that you can use in a Macromedia Flex application, if appropriate.
· Appendix A, "Deprecated Flash 4 operators," on page 809 lists all the ActionScript operators
and their associativity.
· Appendix B, "Keyboard Keys and Key Code Values," on page 811 lists all the keys on a
standard keyboard and the corresponding ASCII key code values that are used to identify the keys in ActionScript.
Typographical conventions
The following typographical conventions are used in this manual:
· ·
Code font indicates Code font italic
ActionScript code.
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 1, "ActionScript Basics," on page 9.
Additional resources
Specific documentation about Macromedia Flash and related products is available separately.
· For information about creating communication applications with Flash Communication
Server, see Developing Communications Applications and Managing Flash Communication Server.
· For information about building Flex applications, see Developing Flex Applications.
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.
6
Introduction: Getting Started with ActionScript
PART I Welcome to ActionScript
PART I
This part includes information on using the ActionScript language. For information on the classes and language elements you can use in your scripts, see Part II, "Reference." Chapter 1: ActionScript Basics . . . . . . ...