The ActionScript 3.0 Quick Reference Guide

Book description

"No matter what your background, the pages that follow will provide you with some excellent knowledge, insight, and even a little bit of wisdom in the realm of Flash and ActionScript. Happy learning!"-- Branden Hall, from the Foreword

Written by Flash insiders with extensive knowledge of the technology, this guide is designed specifically to help Flash designers and developers make the leap from ActionScript 2.0 to the new object-oriented ActionScript 3.0 quickly and painlessly. Formatted so you can find any topic easily, ActionScript 3.0 Quick Reference Guide explains:

  • Object-oriented programming (OOP) concepts, such as packages and classes
  • ActionScript 3.0 features and player enhancements that improve performance
  • Workflow differences between ActionScript 2.0 and ActionScript 3.0 including tools, code editing, component sets, and image and font rendering
  • Where did it go? A guide to help you find familiar features in ActionScript 3.0, such as global functions, operators, properties, and statements
  • How do I? Step-by-step solutions for performing tasks with ActionScript 3.0, including input, sound, video, display, events, text, and more

Also included are overviews of Flash and ActionScript features and workflows. ActionScript 3.0 is a huge upgrade to Flash's programming language -- and this guide helps you upgrade your skills to match it.

Publisher resources

View/Submit Errata

Table of contents

  1. Dedication
  2. A Note Regarding Supplemental Files
  3. Foreword
  4. Preface
    1. What Sets This Book Apart
    2. What’s in This Book
      1. Part I: Introduction to ActionScript 3.0
      2. Part II: ActionScript and the Flash CS4 Authoring Tool
      3. Part III: How Do I?
      4. Part IV: Migration
    3. What’s Not in This Book
    4. Conventions Used in This Book
    5. This Book’s Example Files
    6. Using Code Examples
    7. Safari® Books Online
    8. How to Contact Us
    9. Acknowledgments
      1. From David
      2. From Rich
  5. I. ActionScript 3.0 Introduced
    1. 1. Introducing ActionScript 3.0
      1. Examining ActionScript 3.0, the Language
        1. Runtime Exceptions
        2. Runtime Types
        3. Sealed Classes
        4. Method Closures
        5. ECMAScript for XML (E4X)
        6. Regular Expressions
        7. Namespaces
        8. New Primitive Types
      2. Exploring Flash Player API Updates
        1. DOM3 Event Model
        2. Display List API
        3. New Sound APIs
        4. Binary Data and Sockets
      3. Understanding Players and Support
      4. Learning ActionScript 3.0 on the Heels of 2.0
      5. Deciding to Migrate or Write Code from Scratch
    2. 2. Discovering What You Need to Work with ActionScript 3.0
      1. Flash CS4 Professional/Flex Builder 3
      2. Flash Player 9 or Higher
        1. Debug Vs. Release Players
        2. Making Sure Users Have the Necessary Version of Flash Player
          1. Using SWFObject
      3. Using Other Code Editors with Flash
        1. Creating DragParrot, a Sample Class File
        2. Coding with Flex Builder 3
        3. Coding with SE|PY
        4. Coding with FlashDevelop
        5. Coding with PrimalScript
    3. 3. Looking at the Changes in ActionScript 3.0
      1. Major Changes and Obsolete Code
        1. Major Changes in the API, Classes, and Language
          1. ActionScript 3.0 is stricter
          2. ActionScript 3.0 encourages programming with purpose
          3. ActionScript 3.0 is more organized, which makes it more efficient
        2. Obsolete Code
          1. on()/onClipEvent()
          2. getProperty()/setProperty()/tellTarget()
          3. attachMovie()/attachSound()
          4. createEmptyMovieClip()/duplicateMovieClip()/createTextField()
          5. eval()
      2. Major Syntax and Structure Changes
        1. Importing and Packages
        2. Namespaces
        3. Data Types and Typing
      3. Additional ActionScript 3.0 Resources
    4. 4. Exploring the Benefits of Using ActionScript 3.0
      1. Performance
        1. Updating the Code to ActionScript 3.0
      2. Efficiency
      3. Consistency
      4. Standards and Portability Among Other Technologies
  6. II. ActionScript and the Flash CS4 Authoring Tool
    1. 5. Creating and Working with Code
      1. Thinking in Terms of the Timeline
      2. New Features in the Actions Panel and Script Windows
        1. Actions Panel
          1. Collapsible code sections
          2. Shortcuts for quickly adding and removing code comments
        2. Script Windows
        3. ActionScript Can No Longer Be Attached to Objects
      3. Setting ActionScript Preferences
        1. Preferences Dialog Box
          1. ActionScript
          2. Auto Format
        2. Flash Publish Settings
      4. Associating FLA Files with AS Files
        1. Code Snippets
        2. Classes
      5. Using Script Assist
    2. 6. Creating a Document Class
    3. 7. Working with Library and Linkage Changes
      1. Linkages Now Reference Classes
        1. Naming Classes
        2. Specifying a Base Class
        3. Writing a Custom Class
        4. Recognizing the Associated Class
        5. Attaching Fonts
    4. 8. Copying Motion as ActionScript 3.0
      1. Copying Motion
      2. Applying Motion to Other Objects
        1. Going Retro for the Sake of XML
        2. Editing the Default XML
        3. Editing the Default ActionScript
    5. 9. Using ActionScript 3.0 Components
      1. Overview of the Component Set
        1. Increased Performance and Reduced File Size
        2. Feature Changes
      2. New and Removed Components
      3. Changes in Writing Code for Components
        1. ColorPicker
        2. Slider
        3. TileList
        4. FLVPlaybackCaptioning and CaptionButton
        5. FullScreenButton
      4. Changing the Appearance of Components
        1. Styling Components with Code
        2. Skinning Components Manually
    6. 10. Making Up for a Reduced Component Set
      1. Working Without Data Components in ActionScript 3.0
        1. Creating an XMLConnector Scenario in ActionScript 2.0
        2. Recreating an XMLConnector Scenario in ActionScript 3.0
        3. Creating a WebServiceConnector Scenario in ActionScript 2.0
        4. Recreating a WebServiceConnector Scenario in ActionScript 3.0
      2. ActionScript 2.0 Components in ActionScript 3.0 SWF Files
      3. Exploring Third-Party UI Components
        1. Yahoo! ASTRA Components
        2. Jumpeye Components
    7. 11. Debugging and Troubleshooting
      1. Debugging Is a Good Thing
      2. Testing Your ActionScript 3.0 Code
        1. Compiler Errors
        2. Compiler Warnings
        3. Runtime Errors
      3. Reviewing Improvements in Debugging Over ActionScript 2.0
        1. Don’t Underestimate trace()
        2. Runtime Errors Displayed in Flash Player 9 and Higher
      4. Exploring the Compiler Errors Panel
        1. Using the Compile Errors Panel to Open Code
        2. Interpreting and Understanding Errors
        3. Identifying Common Errors and What They Mean
          1. Be careful where you type your code
          2. Remember to omit property underscores
          3. Referencing movie clip’s parent requires explicit conversion (casting)
          4. Variables can be declared only once per timeline or class
          5. Undeclared timeline variables cannot be referenced
          6. Properties and methods cannot be referenced from a null reference
        4. Troubleshooting
      5. Using the Enhanced Debugging Workspace
        1. Using the Debugger Workspace
          1. Breakpoints
        2. Stepping Through a Debugging Example
        3. Debugging Remotely
        4. Logging trace() Statements from a Browser
  7. III. How Do I?
    1. 12. How Do I Draw with Code?
      1. 12.0 Introduction
      2. 12.1 Creating a Display Object Dynamically
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 12.2 Referencing an Object’s Graphics Property
        1. Problem
        2. Solution
        3. Discussion
      4. 12.3 Defining a Line Style
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 12.4 Drawing a Line
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 12.5 Drawing a Curve
        1. Problem
        2. Solution
        3. Discussion
      7. 12.6 Defining a Fill Style
        1. Problem
        2. Solution
        3. Discussion
      8. 12.7 Drawing a Rectangle
        1. Problem
        2. Solution
        3. Discussion
      9. 12.8 Drawing a Rectangle with Rounded Corners
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 12.9 Drawing a Circle
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 12.10 Creating a Gradient Fill
        1. Problem
        2. Solution
        3. Discussion
      12. 12.11 Using a Drawn Shape as a Dynamic Mask
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 12.12 Caching Vector as Bitmap
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 12.13 Applying a Simple Bitmap Filter
        1. Problem
        2. Solution
        3. Discussion
    2. 13. How Do I Work with the Display List?
      1. 13.0 Introduction
      2. 13.1 Choosing Which Type of Display Object to Use
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 13.2 Creating a New Display Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 13.3 Adding a Display Object to the Display List
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 13.4 Specifying the Depth of a Display Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 13.5 Finding a Display Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 13.6 Removing a Display Object from the Display List
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 13.7 Working with Children of a Display Object Container
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 13.8 Working with Parents of a Display Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 13.9 Casting a Display Object from One Type to Another
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 13.10 Changing the Parent of a Display Object
        1. Problem
        2. Solution
        3. Discussion
      12. 13.11 Referencing the Stage Through a Display Object
        1. Problem
        2. Solution
        3. Discussion
    3. 14. How Do I Work with Events?
      1. 14.0 Introduction
      2. 14.1 Understanding Event Listeners
        1. Problem
        2. Solution
        3. Discussion
      3. 14.2 Capturing Mouse Events
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 14.3 Understanding Event Flow
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 14.4 Using Event Bubbling
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 14.5 Using the target and currentTarget Event Properties
        1. Problem
        2. Solution
        3. Discussion
      7. 14.6 Simulating a Mouse Up Outside Event
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 14.7 Capturing Frame Events
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 14.8 Improving Performance by Removing Event Listeners
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 14.9 Capturing Keyboard Events
        1. Problem
        2. Solution
        3. Discussion
      11. 14.10 Capturing Stage Events
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 14.11 Using a Timer to Dispatch Events
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 14.12 Dispatching Your Own Events
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 14.13 Manually Calling Event Listener Functions
        1. Problem
        2. Solution
        3. Discussion
      15. 14.14 Capturing an Event Before It Reaches Its Target
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 14.15 Setting the Execution Order of Events
        1. Problem
        2. Solution
        3. Discussion
      17. 14.16 Using Weak Listeners
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    4. 15. How Do I Work with Text?
      1. 15.0 Introduction
      2. 15.1 Creating a Text Field
        1. Problem
        2. Solution
        3. Discussion
      3. 15.2 Styling a Text Field
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 15.3 Creating a Password Field
        1. Problem
        2. Solution
        3. Discussion
      5. 15.4 Focusing a Text Field
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 15.5 Populating a Text Field
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 15.6 Automatically Sizing a Text Field
        1. Problem
        2. Solution
        3. Discussion
      8. 15.7 Scrolling a Text Field
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 15.8 Using Embedded Fonts
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 15.9 Formatting Text Using TextFormat
        1. Problem
        2. Solution
        3. Discussion
      11. 15.10 Formatting Text Using HTML
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 15.11 Formatting Text Using CSS
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 15.12 Adding Hyperlinks to Text
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 15.13 Triggering ActionScript from HTML Links
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 15.14 Selecting Text
        1. Problem
        2. Solution
        3. Discussion
    5. 16. How Do I Work with XML?
      1. 16.0 Introduction
      2. 16.1 Creating an XML Object
        1. Problem
        2. Solution
        3. Discussion
      3. 16.2 Loading XML
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 16.3 Reading an Element Node
        1. Problem
        2. Solution
        3. Discussion
      5. 16.4 Reading a Text Node
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 16.5 Working with Multiple Nodes of the Same Name
        1. Problem
        2. Solution
        3. Discussion
      7. 16.6 Reading an Attribute
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 16.7 Finding Content Using Shorthand
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 16.8 Finding Content Using Conditionals
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 16.9 Reading HTML or Entities in XML Nodes
        1. Problem
        2. Solution
        3. Discussion
      11. 16.10 Deleting XML
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 16.11 Writing XML
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 16.12 Writing XML with Variables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 16.13 Sending and Loading XML
        1. Problem
        2. Solution
        3. Discussion
          1. ActionScript
          2. PHP
    6. 17. How Do I Work with External Assets?
      1. 17.0 Introduction
      2. 17.1 Loading and Applying a Cascading Style Sheet
        1. Problem
        2. Solution
        3. Discussion
          1. HTML: demo.html
          2. CSS: demo.css
        4. See Also
      3. 17.2 Loading and Displaying an Image or SWF File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 17.3 Communicating with an ActionScript 3.0 Loaded SWF
        1. Problem
        2. Solution
        3. Discussion
          1. Loadee: loadee.swf
          2. Loader: loader.swf
        4. See Also
      5. 17.4 Communicating with an ActionScript 2.0 Loaded SWF
        1. Problem
        2. Solution
        3. Discussion
          1. Loader: as3.swf
          2. Loadee: as2.swf
        4. See Also
      6. 17.5 Unloading an Image or SWF File
        1. Problem
        2. Solution
        3. Discussion
          1. Loadee: loadee.swf
          2. Loader: loader.swf
          3. But wait...there’s more!
          4. Enter frame events
          5. Timers
          6. Streams and connections
          7. A step in the right direction
        4. See Also
      7. 17.6 Loading and Playing a Sound
        1. Problem
        2. Solution
        3. Discussion
      8. 17.7 Setting the Volume and Pan of a Sound
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 17.8 Visualizing the Amplitude of a Sound
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 17.9 Unloading a Sound
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 17.10 Loading and Playing a Video
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 17.11 Unloading a Video
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
  8. IV. Migration
    1. 18. A Sample Migration
      1. A Simple Particle System
      2. ActionScript 2.0
        1. Main Timeline
        2. Particles Class
      3. ActionScript 3.0
        1. Main Timeline
        2. Particles Class
      4. Migration Sample Summary
    2. 19. Where Did It Go?
      1. Introduction
        1. What’s Included
        2. What’s Not Included
      2. Code Comparisons
        1. Language Fundamentals
          1. Examining and using default values
          2. Referencing objects by evaluated expression
          3. Creating global variables and functions
          4. Accessing the root of a SWF file
          5. Using delegates
        2. Display
          1. Accessing the Stage
          2. Accessing a parent
          3. Creating an empty movie clip
          4. Adding a library movie clip to the stage
          5. Duplicating a movie clip
          6. Creating a bitmap
          7. Adding a library bitmap to the stage
          8. Checking the level of a display object
          9. Getting the highest unused depth
          10. Swapping display object depths
          11. Accessing a display object by name
          12. Removing a display object
          13. Using the drawing API
          14. Checking for display object collisions
          15. Assigning a mask to movie clip
        3. Events
          1. Using event handlers
          2. Adding and removing listeners
          3. Enabling event dispatching
          4. Dispatching events
          5. Trapping a mouse up event outside a display object’s boundaries
        4. Text
          1. Creating a new text field
          2. Populating a text field with plain text
          3. Populating a text field with HTML
          4. Setting a default text format
          5. Using a text field as a variable
          6. Scrolling a text field
          7. Triggering an ActionScript function with a hyperlink
        5. Sound
          1. Loading and playing an external sound
          2. Playing an internal sound from the library
          3. Stopping a sound
          4. Getting or setting a sound’s volume or pan
          5. Getting a sound’s duration
          6. Getting a sound’s current time
          7. Getting a loaded sound’s bytes loaded or total bytes
          8. Stopping all sounds
          9. Setting the buffer time of loaded sounds
        6. Network
          1. Using FlashVars
          2. Getting the URL of a SWF file
          3. Loading and unloading an image or SWF file using loadMovie
          4. Loading and unloading an image or SWF file using MovieClipLoader
          5. Loading variables using LoadVars
          6. Sending variables using LoadVars
          7. Connecting to a URL in a web browser
        7. Miscellaneous
          1. Examining property underscores and name changes
          2. Using event and constant names
          3. Using Intervals and Timeouts
          4. Getting and setting the year of a date instance
          5. Accessing private namespaces
  9. Index
  10. About the Authors
  11. Colophon
  12. Copyright

Product information

  • Title: The ActionScript 3.0 Quick Reference Guide
  • Author(s): Jen deHaan, David Stiller, Darren Richardson, Rich Shupe
  • Release date: October 2008
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596517359