Essential ActionScript 3.0

Book description

ActionScript 3.0 is a huge upgrade to Flash's programming language. The enhancements to ActionScript's performance, feature set, ease of use, cleanliness, and sophistication are considerable. Essential ActionScript 3.0 focuses on the core language and object-oriented programming, along with the Flash Player API. Essential ActionScript has become the #1 resource for the Flash and ActionScript development community, and the reason is the author, Colin Moock. Many people even refer to it simply as "The Colin Moock book."

And for good reason: No one is better at turning ActionScript inside out, learning its nuances and capabilities, and then explaining everything in such an accessible way. Colin Moock is not just a talented programmer and technologist; he's also a gifted teacher.

Essential ActionScript 3.0 is a radically overhauled update to Essential ActionScript 2.0. True to its roots, the book once again focuses on the core language and object-oriented programming, but also adds a deep look at the centerpiece of Flash Player's new API: display programming. Enjoy hundreds of brand new pages covering exciting new language features, such as the DOM-based event architecture, E4X, and namespaces--all brimming with real-world sample code.

The ActionScript 3.0 revolution is here, and Essential ActionScript 3.0's steady hand is waiting to guide you through it.

Adobe Developer Library is a co-publishing partnership between O'Reilly Media and Adobe Systems, Inc. and is designed to produce the number one information resources for developers who use Adobe technologies. Created in 2006, the Adobe Developer Library is the official source for comprehensive learning solutions to help developers create expressive and interactive web applications that can reach virtually anyone on any platform. With top-notch books and innovative online resources covering the latest in rich Internet application development, the Adobe Developer Library offers expert training and in-depth resources, straight from the source.

Table of contents

  1. Special Upgrade Offer
  2. Foreword
  3. Preface
    1. Beginners Welcome
    2. Expert Guidance
    3. What’s In This Book
    4. What’s Not In This Book
    5. Authoring Tool Agnosticism
    6. ActionScript Overview
      1. The Core Language
      2. Flash Runtime Clients
      3. Runtime APIs
      4. Components
      5. The Flash File Format (SWF)
      6. ActionScript Development Tools
    7. This Book’s Example Files
    8. Using Code Examples
    9. Typographical Conventions
    10. How to Contact Us
    11. Acknowledgments
  4. I. ActionScript from the Ground Up
    1. 1. Core Concepts
      1. 1.1. Tools for Writing ActionScript Code
      2. 1.2. Flash Client Runtime Environments
      3. 1.3. Compilation
        1. 1.3.1. Just-In-Time Compilation
      4. 1.4. Quick Review
      5. 1.5. Classes and Objects
      6. 1.6. Creating a Program
      7. 1.7. Packages
      8. 1.8. Defining a Class
        1. 1.8.1. Access Control Modifiers for Classes
      9. 1.9. Virtual Zoo Review
      10. 1.10. Constructor Methods
      11. 1.11. Creating Objects
        1. 1.11.1. Literal Syntax
        2. 1.11.2. Object Creation Example: Adding a Pet to the Zoo
      12. 1.12. Variables and Values
        1. 1.12.1. Local Variables
        2. 1.12.2. Instance Variables
          1. 1.12.2.1. Access-control modifiers for instance variables
      13. 1.13. Constructor Parameters and Arguments
      14. 1.14. Expressions
      15. 1.15. Assigning One Variable’s Value to Another
        1. 1.15.1. Copies and References
      16. 1.16. An Instance Variable for Our Pet
      17. 1.17. Instance Methods
        1. 1.17.1. Access Control Modifiers for Instance Methods
        2. 1.17.2. Method Parameters and Arguments
        3. 1.17.3. Method Return Values
        4. 1.17.4. Method Signatures
      18. 1.18. Members and Properties
      19. 1.19. Virtual Zoo Review
      20. 1.20. Break Time!
    2. 2. Conditionals and Loops
      1. 2.1. Conditionals
        1. 2.1.1. The if Statement
          1. 2.1.1.1. An if statement with no else
          2. 2.1.1.2. Chaining if statements
        2. 2.1.2. The switch Statement
      2. 2.2. Loops
        1. 2.2.1. The while Statement
        2. 2.2.2. Processing Lists with Loops
        3. 2.2.3. Ending a Loop with the break Statement
        4. 2.2.4. The do-while Statement
        5. 2.2.5. The for Statement
      3. 2.3. Boolean Logic
        1. 2.3.1. Logical OR
        2. 2.3.2. Logical AND
        3. 2.3.3. Logical NOT
      4. 2.4. Back to Classes and Objects
    3. 3. Instance Methods Revisited
      1. 3.1. Omitting the this Keyword
        1. 3.1.1. Managing Parameter/Variable Name Conflicts
      2. 3.2. Bound Methods
      3. 3.3. Using Methods to Examine and Modify an Object’s State
      4. 3.4. Get and Set Methods
      5. 3.5. Handling an Unknown Number of Parameters
      6. 3.6. Up Next: Class-Level Information and Behavior
    4. 4. Static Variables and Static Methods
      1. 4.1. Static Variables
      2. 4.2. Constants
      3. 4.3. Static Methods
        1. 4.3.1. The Class Initializer
      4. 4.4. Class Objects
      5. 4.5. C++ and Java Terminology Comparison
      6. 4.6. On to Functions
    5. 5. Functions
      1. 5.1. Package-Level Functions
        1. 5.1.1. Global Functions
      2. 5.2. Nested Functions
      3. 5.3. Source-File-Level Functions
      4. 5.4. Accessing Definitions from Within a Function
      5. 5.5. Functions as Values
      6. 5.6. Function Literal Syntax
      7. 5.7. Recursive Functions
      8. 5.8. Using Functions in the Virtual Zoo Program
      9. 5.9. Back to Classes
    6. 6. Inheritance
      1. 6.1. A Primer on Inheritance
        1. 6.1.1. Static Methods and Static Variables Not Inherited
      2. 6.2. Overriding Instance Methods
        1. 6.2.1. Invoking an Overridden Instance Method
      3. 6.3. Constructor Methods in Subclasses
      4. 6.4. Preventing Classes from Being Extended and Methods from Being Overridden
      5. 6.5. Subclassing Built-in Classes
      6. 6.6. The Theory of Inheritance
        1. 6.6.1. Why Inheritance?
        2. 6.6.2. Polymorphism and Dynamic Binding
        3. 6.6.3. Inheritance Versus Composition
          1. 6.6.3.1. Is-A, Has-A, and Uses-A
          2. 6.6.3.2. When to use composition over inheritance
      7. 6.7. Abstract Not Supported
      8. 6.8. Using Inheritance in the Virtual Zoo Program
        1. 6.8.1. Creating Types of Pet Food
        2. 6.8.2. Preparing VirtualZoo for Onscreen Display
      9. 6.9. Virtual Zoo Program Code
      10. 6.10. It’s Runtime!
    7. 7. Compiling and Running a Program
      1. 7.1. Compiling with the Flash Authoring Tool
      2. 7.2. Compiling with Flex Builder 2
        1. 7.2.1. Moving the Main Class to the Unnamed Package
        2. 7.2.2. Compiling the Program
        3. 7.2.3. Running the Program
      3. 7.3. Compiling with mxmlc
      4. 7.4. Compiler Restrictions
      5. 7.5. The Compilation Process and the Classpath
      6. 7.6. Strict-Mode Versus Standard-Mode Compilation
        1. 7.6.1. Enabling Standard-Mode Compilation in Flex Builder 2
        2. 7.6.2. Enabling Standard-Mode Compilation in the Flash Authoring Tool
      7. 7.7. The Fun’s Not Over
    8. 8. Datatypes and Type Checking
      1. 8.1. Datatypes and Type Annotations
        1. 8.1.1. Compatible Types
        2. 8.1.2. Detecting Type Mismatch Errors with Type Annotations
      2. 8.2. Untyped Variables, Parameters, Return Values, and Expressions
      3. 8.3. Strict Mode’s Three Special Cases
      4. 8.4. Warnings for Missing Type Annotations
      5. 8.5. Detecting Reference Errors at Compile Time
      6. 8.6. Casting
        1. 8.6.1. Avoiding Unwanted Type Mismatch Errors
        2. 8.6.2. Upcasting and Downcasting
        3. 8.6.3. Using the as Operator to Cast to Date and Array
      7. 8.7. Conversion to Primitive Types
      8. 8.8. Default Variable Values
      9. 8.9. null and undefined
      10. 8.10. Datatypes in the Virtual Zoo
      11. 8.11. More Datatype Study Coming Up
    9. 9. Interfaces
      1. 9.1. The Case for Interfaces
      2. 9.2. Interfaces and Multidatatype Classes
      3. 9.3. Interface Syntax and Use
        1. 9.3.1. Interface Naming Conventions
        2. 9.3.2. Interface Inheritance
        3. 9.3.3. Marker Interfaces
      4. 9.4. Another Multiple-Type Example
      5. 9.5. More Essentials Coming
    10. 10. Statements and Operators
      1. 10.1. Statements
      2. 10.2. Operators
        1. 10.2.1. Number of Operands
        2. 10.2.2. Operator Precedence
        3. 10.2.3. Operator Associativity
        4. 10.2.4. Datatypes and Operators
        5. 10.2.5. Operator Overview
      3. 10.3. Up Next: Managing Lists of Information
    11. 11. Arrays
      1. 11.1. What Is an Array?
      2. 11.2. The Anatomy of an Array
        1. 11.2.1. Array Elements
        2. 11.2.2. Array Element Indexing
        3. 11.2.3. Array Size
      3. 11.3. Creating Arrays
        1. 11.3.1. Creating Arrays with Array Literals
        2. 11.3.2. Creating Arrays with the new Operator
      4. 11.4. Referencing Array Elements
        1. 11.4.1. Retrieving an Element’s Value
        2. 11.4.2. Setting an Element’s Value
      5. 11.5. Determining the Size of an Array
      6. 11.6. Adding Elements to an Array
        1. 11.6.1. Adding New Elements Directly
        2. 11.6.2. Adding New Elements with the length Variable
        3. 11.6.3. Adding New Elements with Array Methods
          1. 11.6.3.1. The push( ) method
          2. 11.6.3.2. The unshift( ) method
          3. 11.6.3.3. The splice( ) method
          4. 11.6.3.4. The concat( ) method
      7. 11.7. Removing Elements from an Array
        1. 11.7.1. Removing Elements with the delete Operator
        2. 11.7.2. Removing Elements with the length Variable
        3. 11.7.3. Removing Elements with Array Methods
          1. 11.7.3.1. The pop( ) method
          2. 11.7.3.2. The shift( ) method
          3. 11.7.3.3. The splice( ) method
      8. 11.8. Checking the Contents of an Array with the toString( ) Method
      9. 11.9. Multidimensional Arrays
      10. 11.10. On to Events
    12. 12. Events and Event Handling
      1. 12.1. ActionScript Event Basics
        1. 12.1.1. Registering an Event Listener for an Event
          1. 12.1.1.1. Step 1: Determine the event type’s name
          2. 12.1.1.2. Step 2: Determine the event object’s datatype
          3. 12.1.1.3. Step 3: Create the event listener
          4. 12.1.1.4. Step 4: Register for the event
          5. 12.1.1.5. Step 5: Wait for the event to occur
        2. 12.1.2. Two More Event Listener Registration Examples
        3. 12.1.3. Unregistering an Event Listener for an Event
        4. 12.1.4. Event Vocabulary Review
      2. 12.2. Accessing the Target Object
      3. 12.3. Accessing the Object That Registered the Listener
      4. 12.4. Preventing Default Event Behavior
      5. 12.5. Event Listener Priority
      6. 12.6. Event Listeners and Memory Management
        1. 12.6.1. Weak Listener References
      7. 12.7. Custom Events
        1. 12.7.1. A Custom “gameOver” Event
        2. 12.7.2. A Custom “toggle” Event
        3. 12.7.3. Preventing Default Behavior for Custom Events
      8. 12.8. Type Weakness in ActionScript’s Event Architecture
      9. 12.9. Handling Events Across Security Boundaries
        1. 12.9.1. Module.swf Listener Registers with Main.swf Object
        2. 12.9.2. Main.Swf Listener Receives Notification for an Event Targeted at a Module.swf Display Object
        3. 12.9.3. An Alternative to allowDomain( ): Shared Events
      10. 12.10. What’s Next?
    13. 13. Exceptions and Error Handling
      1. 13.1. The Exception-Handling Cycle
      2. 13.2. Handling Multiple Types of Exceptions
        1. 13.2.1. Determining Exception Type Granularity
          1. 13.2.1.1. Options 1 and 2: Using a single custom-exception type
          2. 13.2.1.2. Option 3: Using configurable debugging messages
          3. 13.2.1.3. Option 4: Multiple custom VirtualPetNameException subclasses
      3. 13.3. Exception Bubbling
        1. 13.3.1. Uncaught Exceptions
      4. 13.4. The finally Block
      5. 13.5. Nested Exceptions
      6. 13.6. Control-Flow Changes in try/catch/finally
      7. 13.7. Handling a Built-in Exception
        1. 13.7.1. Error Events for Problem Conditions
      8. 13.8. More Gritty Work Ahead
    14. 14. Garbage Collection
      1. 14.1. Eligibility for Garbage Collection
      2. 14.2. Incremental Mark and Sweep
      3. 14.3. Disposing of Objects Intentionally
      4. 14.4. Deactivating Objects
      5. 14.5. Garbage Collection Demonstration
      6. 14.6. On to ActionScript Backcountry
    15. 15. Dynamic ActionScript
      1. 15.1. Dynamic Instance Variables
        1. 15.1.1. Processing Dynamic Instance Variables with for-each-in and for-in Loops
      2. 15.2. Dynamically Adding New Behavior to an Instance
      3. 15.3. Dynamic References to Variables and Methods
      4. 15.4. Using Dynamic Instance Variables to Create Lookup Tables
        1. 15.4.1. Making Lookup Tables with Object Literals
      5. 15.5. Using Functions to Create Objects
      6. 15.6. Using Prototype Objects to Augment Classes
      7. 15.7. The Prototype Chain
      8. 15.8. Onward!
    16. 16. Scope
      1. 16.1. Global Scope
      2. 16.2. Class Scope
      3. 16.3. Static Method Scope
      4. 16.4. Instance Method Scope
      5. 16.5. Function Scope
      6. 16.6. Scope Summary
      7. 16.7. The Internal Details
      8. 16.8. Expanding the Scope Chain via the with Statement
      9. 16.9. On to Namespaces
    17. 17. Namespaces
      1. 17.1. Namespace Vocabulary
      2. 17.2. ActionScript Namespaces
      3. 17.3. Creating Namespaces
        1. 17.3.1. Choosing the Namespace URI
        2. 17.3.2. Defining the Namespace
        3. 17.3.3. Explicit Versus Implicit URIs
        4. 17.3.4. Namespace Terminology Review
      4. 17.4. Using a Namespace to Qualify Variable and Method Definitions
        1. 17.4.1. User-Defined Namespace Attributes in the Top-Level of a Class Only
      5. 17.5. Qualified Identifiers
        1. 17.5.1. Expanded Names
      6. 17.6. A Functional Namespace Example
      7. 17.7. Namespace Accessibility
        1. 17.7.1. Accessibility of Package-Level Namespace Definitions
        2. 17.7.2. Accessibility of Class-Level Namespace Definitions
        3. 17.7.3. Accessibility of Function-Level Namespace Definitions
      8. 17.8. Qualified-Identifier Visibility
      9. 17.9. Comparing Qualified Identifiers
      10. 17.10. Assigning and Passing Namespace Values
        1. 17.10.1. Assigning a Namespace Value to a Variable
        2. 17.10.2. Namespaces as Method Arguments and Return Values
        3. 17.10.3. A Namespace Value Example
      11. 17.11. Open Namespaces and the use namespace Directive
        1. 17.11.1. Open Namespaces and Scope
        2. 17.11.2. Opening Multiple Namespaces
      12. 17.12. Namespaces for Access-Control Modifiers
        1. 17.12.1. Import Opens Public Namespaces
      13. 17.13. Applied Namespace Examples
        1. 17.13.1. Example: Framework-Internal Visibility
        2. 17.13.2. Example: Permission-Based Access Control
        3. 17.13.3. Example: Program Modes
      14. 17.14. Final Core Topics
    18. 18. XML and E4X
      1. 18.1. Understanding XML Data as a Hierarchy
      2. 18.2. Representing XML Data in E4X
      3. 18.3. Creating XML Data with E4X
      4. 18.4. Accessing XML Data
        1. 18.4.1. Accessing the Root XML Node
        2. 18.4.2. Accessing Child Nodes
        3. 18.4.3. Accessing Text Nodes
        4. 18.4.4. Accessing Parent Nodes
        5. 18.4.5. Accessing Sibling Nodes
        6. 18.4.6. Accessing Attributes
        7. 18.4.7. Accessing Comments and Processing Instructions
        8. 18.4.8. Accessing Attributes and Elements Whose Names Contain Reserved Characters
        9. 18.4.9. Treating XMLList as XML, Revisited
      5. 18.5. Processing XML with for-each-in and for-in
      6. 18.6. Accessing Descendants
      7. 18.7. Filtering XML Data
      8. 18.8. Traversing XML Trees
      9. 18.9. Changing or Creating New XML Content
        1. 18.9.1. Changing the Contents of an Element
        2. 18.9.2. Changing an Attribute Value
        3. 18.9.3. Replacing an Entire Element
        4. 18.9.4. Adding New Attributes and Elements
          1. 18.9.4.1. Adding a new child after all existing children
          2. 18.9.4.2. Adding a new child after a specific existing child
          3. 18.9.4.3. Adding a new child before a specific existing child
          4. 18.9.4.4. Adding a new child before all existing children
        5. 18.9.5. Deleting Elements and Attributes
        6. 18.9.6. References to Parts of a Document Are Not Live
        7. 18.9.7. Using XML Entities for Special Characters
        8. 18.9.8. Assigning Values to an XMLList
      10. 18.10. Loading XML Data
      11. 18.11. Working with XML Namespaces
        1. 18.11.1. Accessing Namespace-Qualified Elements and Attributes
        2. 18.11.2. Creating Namespace-Qualified Elements and Attributes
      12. 18.12. Converting XML and XMLList to a String
        1. 18.12.1. Converting XMLList to a String
        2. 18.12.2. Converting an XML Element to a String
        3. 18.12.3. Converting an Attribute to a String
        4. 18.12.4. Converting Comments and Processing-Instructions to Strings
      13. 18.13. Determining Equality in E4X
        1. 18.13.1. XML Equality
        2. 18.13.2. XMLList Equality
        3. 18.13.3. QName Equality
        4. 18.13.4. Namespace Equality
      14. 18.14. More to Learn
    19. 19. Flash Player Security Restrictions
      1. 19.1. What’s Not in This Chapter
      2. 19.2. The Local Realm, the Remote Realm, and Remote Regions
      3. 19.3. Security-Sandbox-Types
        1. 19.3.1. How Security-Sandbox-Types Are Assigned
      4. 19.4. Security Generalizations Considered Harmful
      5. 19.5. Restrictions on Loading Content, Accessing Content as Data, Cross-Scripting, and Loading Data
        1. 19.5.1. Loading Content
        2. 19.5.2. Accessing Content as Data
        3. 19.5.3. Cross-Scripting
        4. 19.5.4. Loading Data
        5. 19.5.5. Restrictions on Loading Content, Accessing Content as Data, Loading Data, and Cross-Scripting
      6. 19.6. Socket Security
      7. 19.7. Example Security Scenarios
        1. 19.7.1. Snoopy Email Attachment—Without Flash Player Security
        2. 19.7.2. Snoopy Email Attachment—With Flash Player Security
        3. 19.7.3. Internal Corporate Information—Without Flash Player Security
        4. 19.7.4. Internal Corporate Information—With Flash Player Security
        5. 19.7.5. Cross-Web Site Information—Without Flash Player Security
        6. 19.7.6. Cross-Web Site Information—With Flash Player Security
      8. 19.8. Choosing a Local Security-Sandbox-Type
        1. 19.8.1. Compiling a Local-with-Filesystem .swf File
        2. 19.8.2. Compiling a Local-with-Networking .swf File
        3. 19.8.3. Granting Local Trust
        4. 19.8.4. Developers Automatically Trusted
        5. 19.8.5. Default Local Security-Sandbox-Type
      9. 19.9. Distributor Permissions (Policy Files)
        1. 19.9.1. Authorizing Loading-Data and Accessing-Content-as-Data Operations
          1. 19.9.1.1. Creating the policy file
          2. 19.9.1.2. Posting the policy file
          3. 19.9.1.3. Obtaining a policy file’s permission to load data
          4. 19.9.1.4. Obtaining a policy file’s permission to access content as data
        2. 19.9.2. Using a Policy File to Authorize Socket Connections
          1. 19.9.2.1. Create the policy file
          2. 19.9.2.2. Socket-based policy-file retrieval
          3. 19.9.2.3. HTTP-based policy-file retrieval
      10. 19.10. Creator Permissions (allowDomain( ))
        1. 19.10.1. Allowing .swf Files Served Over HTTP to Cross-Script .swf Files Served Over HTTPS
      11. 19.11. Import Loading
      12. 19.12. Handling Security Violations
      13. 19.13. Security Domains
        1. 19.13.1. Ambiguous Use of the Term “Sandbox”
      14. 19.14. Two Common Security-Related Development Issues
        1. 19.14.1. Accessing Internet Subdomains
        2. 19.14.2. Accessing the Loader Class’s Instance Variable Content
      15. 19.15. On to Part II!
  5. II. Display and Interactivity
    1. 20. The Display API and the Display List
      1. 20.1. Display API Overview
        1. 20.1.1. Extending the Core-Display Class Hierarchy
      2. 20.2. The Display List
        1. 20.2.1. Containers and Depths
        2. 20.2.2. Removing Assets from Containers
        3. 20.2.3. Removing Assets from Memory
        4. 20.2.4. Removing All Children
        5. 20.2.5. Reparenting Assets
        6. 20.2.6. Traversing Objects in a Display Hierarchy
        7. 20.2.7. Manipulating Objects in Containers Collectively
        8. 20.2.8. Descendant Access to a .swf File’s Main Class Instance
          1. 20.2.8.1. The rebirth of _root
          2. 20.2.8.2. Whither _level0?
      3. 20.3. Containment Events
        1. 20.3.1. The Event.ADDED and Event.REMOVED Events
        2. 20.3.2. A Real-World Containment-Event Example
        3. 20.3.3. The ADDED_TO_STAGE and REMOVED_FROM_STAGE Events
          1. 20.3.3.1. Custom Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE events
      4. 20.4. Custom Graphical Classes
      5. 20.5. Go with the Event Flow
    2. 21. Events and Display Hierarchies
      1. 21.1. Hierarchical Event Dispatch
      2. 21.2. Event Dispatch Phases
      3. 21.3. Event Listeners and the Event Flow
        1. 21.3.1. Registering an Ancestor Listener for the Capture Phase
        2. 21.3.2. Registering an Ancestor Listener for the Bubbling Phase
        3. 21.3.3. Registering an Ancestor Listener for Both the Capture Phase and the Bubbling Phase
        4. 21.3.4. Registering a Listener with the Event Target
        5. 21.3.5. The Dual Purpose of the useCapture Parameter
        6. 21.3.6. Removing Event Listeners
      4. 21.4. Using the Event Flow to Centralize Code
      5. 21.5. Determining the Current Event Phase
      6. 21.6. Distinguishing Events Targeted at an Object from Events Targeted at That Object’s Descendants
      7. 21.7. Stopping an Event Dispatch
      8. 21.8. Event Priority and the Event Flow
      9. 21.9. Display-Hierarchy Mutation and the Event Flow
        1. 21.9.1. Event Listener List Mutation
      10. 21.10. Custom Events and the Event Flow
      11. 21.11. On to Input Events
    3. 22. Interactivity
      1. 22.1. Mouse-Input Events
        1. 22.1.1. Flash Player’s Built-in Mouse Events
        2. 22.1.2. Registering for Mouse Events
        3. 22.1.3. Mouse Events and Overlapping Display Objects
        4. 22.1.4. Finding the Mouse Pointer’s Position
        5. 22.1.5. Handling Mouse Events “Globally”
      2. 22.2. Focus Events
        1. 22.2.1. Focusing Objects Programmatically
        2. 22.2.2. Focusing Objects with the Keyboard
        3. 22.2.3. Focusing Objects with the Mouse
          1. 22.2.3.1. Handling descendant focus through a single ancestor
        4. 22.2.4. Flash Player’s Focus Events
      3. 22.3. Keyboard-Input Events
        1. 22.3.1. Global Keyboard-Event Handling
        2. 22.3.2. Object-Specific Keyboard-Event Handling
        3. 22.3.3. Determining the Most Recently Pressed or Released Key
          1. 22.3.3.1. Multilocation keys
        4. 22.3.4. Detecting Multiple Simultaneous Key Presses
        5. 22.3.5. Mouse Events and Modifier Keys
        6. 22.3.6. Determining the Character Associated with a Key
      4. 22.4. Text-Input Events
        1. 22.4.1. The TextEvent.TEXT_INPUT and Event.CHANGE Events
        2. 22.4.2. The Event.SCROLL Event
        3. 22.4.3. The TextEvent.LINK Event
      5. 22.5. Flash Player-Level Input Events
        1. 22.5.1. The Event.ACTIVATE and Event.DEACTIVATE Events
        2. 22.5.2. The Event.RESIZE Event
        3. 22.5.3. The Event.MOUSE_LEAVE Event
      6. 22.6. From the Program to the Screen
    4. 23. Screen Updates
      1. 23.1. Scheduled Screen Updates
        1. 23.1.1. No Screen Updates Within Code Blocks
        2. 23.1.2. Setting the Frame Rate
        3. 23.1.3. Designated Frame Rate Versus Actual Frame Rate
      2. 23.2. Post-Event Screen Updates
        1. 23.2.1. Post-Event Updates for Timer Events
        2. 23.2.2. Automatic Post-Event Screen Updates
      3. 23.3. Redraw Region
      4. 23.4. Optimization with the Event.RENDER Event
      5. 23.5. Let’s Make It Move!
    5. 24. Programmatic Animation
      1. 24.1. No Loops
      2. 24.2. Animating with the ENTER_FRAME Event
        1. 24.2.1. Frame Rate’s Effect on Event.ENTER_FRAME Animations
      3. 24.3. Animating with the TimerEvent.TIMER Event
        1. 24.3.1. Frame Rate’s Effect on Timer
      4. 24.4. Choosing Between Timer and Event.ENTER_FRAME
      5. 24.5. A Generalized Animator
      6. 24.6. Velocity-Based Animation
      7. 24.7. Moving On to Strokes ‘n’ Fills
    6. 25. Drawing with Vectors
      1. 25.1. Graphics Class Overview
      2. 25.2. Drawing Lines
      3. 25.3. Drawing Curves
      4. 25.4. Drawing Shapes
      5. 25.5. Removing Vector Content
      6. 25.6. Example: An Object-Oriented Shape Library
      7. 25.7. From Lines to Pixels
    7. 26. Bitmap Programming
      1. 26.1. The BitmapData and Bitmap Classes
      2. 26.2. Pixel Color Values
      3. 26.3. Creating a New Bitmap Image
      4. 26.4. Loading an External Bitmap Image
      5. 26.5. Examining a Bitmap
        1. 26.5.1. getPixel32() Versus getPixel( )
        2. 26.5.2. Transparency’s Effect on Color-Value Retrieval
        3. 26.5.3. ColorPicker: A getPixel32( ) Example
        4. 26.5.4. Retrieving the Color of a Region of Pixels
        5. 26.5.5. Other Examination Tools
      6. 26.6. Modifying a Bitmap
        1. 26.6.1. Improve Performance with BitmapData.lock( )
        2. 26.6.2. ScribbleAS3: A setPixel32( ) Example
        3. 26.6.3. Assigning the Color of a Region of Pixels
        4. 26.6.4. Other Manipulation Tools
        5. 26.6.5. Resizing a Bitmap
      7. 26.7. Copying Graphics to a BitmapData Object
        1. 26.7.1. The BitmapData Class’s Instance Method draw( )
          1. 26.7.1.1. How draw( ) handles Alpha channel values
          2. 26.7.1.2. No arbitrary screen captures
        2. 26.7.2. The BitmapData Class’s Instance Method copyPixels( )
      8. 26.8. Applying Filters and Effects
        1. 26.8.1. Applying Filters
      9. 26.9. Freeing Memory Used by Bitmaps
      10. 26.10. Words, Words, Words
    8. 27. Text Display and Input
      1. 27.1. Creating and Displaying Text
        1. 27.1.1. Word Wrapping
        2. 27.1.2. Automatic Resizing
        3. 27.1.3. Rotated, Skewed, and Transparent Text Requires Embedded Fonts
      2. 27.2. Modifying a Text Field’s Content
      3. 27.3. Formatting Text Fields
        1. 27.3.1. Formatting Text with the TextFormat Class
          1. 27.3.1.1. Available TextFormat variables
          2. 27.3.1.2. Embedded font warning: Bold and italic require separate fonts
          3. 27.3.1.3. setTextFormat( ) does not apply to future text assignments
          4. 27.3.1.4. Applying paragraph-level formatting
          5. 27.3.1.5. Retrieving formatting information for a span of characters
          6. 27.3.1.6. Default formatting for text fields
        2. 27.3.2. Formatting Text with HTML
          1. 27.3.2.1. Entity support
          2. 27.3.2.2. Quoting attribute values
          3. 27.3.2.3. Interactions between the text and htmlText variables
          4. 27.3.2.4. Unrecognized tags and attributes
        3. 27.3.3. Formatting Text with the StyleSheet Class
          1. 27.3.3.1. Notable style sheet limitations in ActionScript
          2. 27.3.3.2. Formatting text with a programmatically created style sheet
          3. 27.3.3.3. Class selectors
          4. 27.3.3.4. Formatting XML tags with CSS
          5. 27.3.3.5. Formatting text with an externally loaded style sheet
      4. 27.4. Fonts and Text Rendering
        1. 27.4.1. Embedding Font Outlines in the Flash Authoring Tool
        2. 27.4.2. Embedding Font Outlines in Flex Builder 2 and mxmlc
        3. 27.4.3. Formatting Text with an Embedded Font
          1. 27.4.3.1. Using bold and italic with embedded fonts
        4. 27.4.4. Loading Fonts at Runtime
      5. 27.5. Missing Fonts and Glyphs
      6. 27.6. Determining Font Availability
      7. 27.7. Determining Glyph Availability
      8. 27.8. Embedded-Text Rendering
        1. 27.8.1. Tweaking the FlashType Renderer
      9. 27.9. Text Field Input
        1. 27.9.1. Text Entry
          1. 27.9.1.1. Formatting user input
        2. 27.9.2. Text Selection
        3. 27.9.3. Hypertext Links
      10. 27.10. Text Fields and the Flash Authoring Tool
      11. 27.11. Loading . . . Please Wait . . .
    9. 28. Loading External Display Assets
      1. 28.1. Using Loader to Load Display Assets at Runtime
        1. 28.1.1. Creating the Loader Instance
        2. 28.1.2. Specifying the Asset’s Location
        3. 28.1.3. Starting the Load Operation
        4. 28.1.4. Accessing the Loaded Asset
        5. 28.1.5. Displaying the Loaded Asset On Screen
        6. 28.1.6. Displaying Load Progress
          1. 28.1.6.1. Why not use Event.OPEN?
        7. 28.1.7. Handling Load Errors
          1. 28.1.7.1. Environment-specific behavior for load failures
          2. 28.1.7.2. Debugging with HTTPStatusEvent
      2. 28.2. Compile-Time Type-Checking for Runtime-Loaded Assets
        1. 28.2.1. Opting Out of Compile-Time Type-Checking
        2. 28.2.2. Give the Compiler Access to the Loaded Class
        3. 28.2.3. Add the Module Class File to Main.swf’s source-path
        4. 28.2.4. Add the Module Class File to Main.swf’s library-path
        5. 28.2.5. Add the Module Class File to Main.swf’s external-library-path
      3. 28.3. Accessing Assets in Multiframe .swf Files
      4. 28.4. Instantiating a Runtime-Loaded Asset
        1. 28.4.1. Instantiating a Loaded .swf File
        2. 28.4.2. Instantiating a Loaded Image
      5. 28.5. Using Socket to Load Display Assets at Runtime
        1. 28.5.1. Server-Side: Sending the Asset
        2. 28.5.2. Client-Side: Receiving the Asset
          1. 28.5.2.1. Creating and connecting to the socket
          2. 28.5.2.2. Placing bytes in a buffer
          3. 28.5.2.3. Creating a display asset from the loaded bytes
      6. 28.6. Removing Runtime Loaded .swf Assets
      7. 28.7. Embedding Display Assets at Compile Time
        1. 28.7.1. A Note on File Size and Memory Consumption
        2. 28.7.2. General [Embed] Syntax
        3. 28.7.3. Supported Asset Types
        4. 28.7.4. Embedding Bitmap Images
        5. 28.7.5. Embedding SVG
        6. 28.7.6. Embedding Entire .swf Files
        7. 28.7.7. Embedding Symbols from Legacy .swf Files
        8. 28.7.8. Embedding Files as Binary Data
        9. 28.7.9. Using getDefinition( ) to Access a Class in an Embedded .swf File
        10. 28.7.10. An [Embed] Example
        11. 28.7.11. Clean the Project to See Changes
      8. 28.8. On to Part III
  6. III. Applied ActionScript Topics
    1. 29. ActionScript and the Flash Authoring Tool
      1. 29.1. The Flash Document
      2. 29.2. Timelines and Frames
        1. 29.2.1. Keyframes and Regular Frames
      3. 29.3. Timeline Scripting
      4. 29.4. The Document Class
        1. 29.4.1. Variable and Function Definitions in Frame Scripts
      5. 29.5. Symbols and Instances
        1. 29.5.1. Types of Symbols
        2. 29.5.2. Movie Clip Symbols
      6. 29.6. Linked Classes for Movie Clip Symbols
      7. 29.7. Accessing Manually Created Symbol Instances
        1. 29.7.1. Instance Names
        2. 29.7.2. Matching Variables for Instance Names
      8. 29.8. Accessing Manually Created Text
      9. 29.9. Programmatic Timeline Control
      10. 29.10. Instantiating Flash Authoring Symbols via ActionScript
      11. 29.11. Instance Names for Programmatically Created Display Objects
      12. 29.12. Linking Multiple Symbols to a Single Superclass
      13. 29.13. The Composition-Based Alternative to Linked Classes
      14. 29.14. Preloading Classes
      15. 29.15. Up Next: Using the Flex Framework
    2. 30. A Minimal MXML Application
      1. 30.1. The General Approach
        1. 30.1.1. Create the Flex Project
        2. 30.1.2. Create the Application Point of Entry
        3. 30.1.3. Trigger the Application Point of Entry
      2. 30.2. A Real UI Component Example
      3. 30.3. Sharing with Your Friends
    3. 31. Distributing a Class Library
      1. 31.1. Sharing Class Source Files
      2. 31.2. Distributing a Class Library as a .swc File
        1. 31.2.1. Creating a .swc-Based Class Library in Flex Builder 2
        2. 31.2.2. Using a .swc-Based Class Library in Flex Builder 2
        3. 31.2.3. Creating a .swc-Based Class Library in the Flash Authoring Tool
        4. 31.2.4. Using a .swc-Based Class Library in the Flash Authoring Tool
      3. 31.3. Distributing a Class Library as a .swf File
        1. 31.3.1. Creating a .swf-Based Class Library in Flex Builder 2
          1. 31.3.1.1. Compiling a .swf file using mxmlc
        2. 31.3.2. Using a .swf-Based Class Library in Flex Builder 2
        3. 31.3.3. Creating a .swf-Based Class Library in the Flash Authoring Tool
        4. 31.3.4. Using a .swf-Based Class Library in Flash CS3
      4. 31.4. But Is It Really Over?
  7. A. The Final Virtual Zoo
  8. Index
  9. About the Author
  10. Colophon
  11. Special Upgrade Offer
  12. Copyright

Product information

  • Title: Essential ActionScript 3.0
  • Author(s): Colin Moock
  • Release date: June 2007
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596526948