Essential ActionScript 2.0

Book description

In September 2003, Macromedia released Flash MX 2004, and with it, ActionScript 2.0, a dramatically improved version of Flash's programming language. ActionScript 2.0 introduces a formal object-oriented programming syntax and methodology for creating Flash applications. From a developer's perspective, the new OOP-based techniques in ActionScript 2.0 make applications more natural to plan and conceptualize, more stable, more reusable across projects, easier to maintain, change, and expand upon, and much more. In short, they enhance the entire development process. In Essential ActionScript 2.0, bestselling author Colin Moock--one of the most universally respected developers in the Flash community--covers everything you'll need to know about the new ActionScript language and its methodologies for producing movies, animation, and applications on the web. Moock guides readers through this important new territory with his trademark easy-to-understand style and expertise. Moock's goal throughout the book is not just to get you to use object-oriented programming in your daily Flash work: he wants you to reap the benefits of OOP; he wants you to understand ActionScript 2.0 completely. And without question, Moock is the author who can make this happen. Essential ActionScript 2.0 begins with a tour of the language, including the fundamentals of object-oriented concepts, syntax, and usage. Those who are new to OOP will learn the basics and how to apply their understanding. Those who are familiar with OOP will leverage their prior experience to learn about Flash-based OOP. The next part of the book shows how to structure entire applications with ActionScript 2.0, teaching you best practices and techniques to build scalable, extensible, stable apps. Next, you'll explore a variety of approaches to various programming situations by applying object-oriented programming strategies, known as design patterns, to Flash. Experienced Flash developers and programmers coming from other languages will enjoy the sheer depth of Moocks's coverage and expertise in Essential ActionScript 2.0. Novice programmers will appreciate the frequent, low-jargon explanations that are often glossed over by advanced programming books. As usual, Moock guarantees quality and accuracy by working closely with Macromedia Flash engineers, including Rebecca Sun, lead developer of ActionScript 2.0. Whether you're ready to make the move to ActionScript 2.0 now or simply assessing it for the future, you'll find everything you need to know within this book. Essential ActionScript 2.0 is the one book every ActionScript coder must own.

Table of contents

  1. Table of Contents (1/2)
  2. Table of Contents (2/2)
  3. Foreword
  4. Preface
    1. This Book Wants You
    2. What This Book Is Not
    3. Who Should (and Shouldn’t) Read This Book
    4. ActionScript 2.0 Versus ActionScript 1.0
    5. Deciphering Flash Versions
    6. Example Files and Resources
    7. Typographical Conventions
    8. Using Code Examples
    9. We’d Like to Hear from You
    10. Acknowledgments
  5. Part I
  6. ActionScript 2.0 Overview
    1. ActionScript 2.0 Features
    2. Features Introduced by Flash Player 7
    3. Flash MX 2004 Version 2 Components
    4. ActionScript 1.0 and 2.0 in Flash Player 6 and 7
      1. Setting a Movie’s ActionScript Version and Player Version
      2. Changes to ActionScript 1.0 in Flash Player 7
      3. Flash 4 Slash Syntax Is Not Supported in ActionScript 2.0
    5. Let’s Go OOP
  7. Object-Oriented ActionScript
    1. Procedural Programming and Object-Oriented Programming
    2. Key Object-Oriented Programming Concepts
      1. Class Syntax
      2. Object Creation
      3. Object Usage
      4. Encapsulation
      5. Datatypes
      6. Inheritance
      7. Packages
      8. Compilation
      9. Starting an Objected-Oriented Application
    3. But How Do I Apply OOP?
    4. On with the Show!
  8. Datatypes and Type Checking (1/2)
  9. Datatypes and Type Checking (2/2)
    1. Why Static Typing?
    2. Type Syntax
      1. Declaring Variable and Property Datatypes
      2. Declaring Method Parameter and Return Value Datatypes
      3. Why Post-Colon Syntax?
    3. Compatible Types
      1. Handling Any Datatype
      2. Compatibility with null and undefined
    4. Built-in Dynamic Classes
    5. Circumventing Type Checking
      1. Creating Parameters That Accept Multiple Types
      2. Allowing Property and Method Creation on a Class’s Instances
      3. Bypassing Type Checking on a Per-Use Basis
    6. Casting
      1. Casting Terminology
      2. Runtime Casting Support
      3. Casting Does Not Affect Method or Property Selection
      4. Casting Versus Conversion
      5. ActionScript 2.0’s Lenient Compile-Time Casting
      6. Problems Casting to String, Number, Boolean, Date, and Array
    7. Datatype Information for Built-in Classes
    8. ActionScript 2.0 Type Checking Gotchas
      1. Global Variables Can’t Be Typed
      2. Type Checking and Timeline Code
      3. Type Checking XML Instances
      4. No Type Checking with the [] Operator
      5. Array Elements and Type Checking
    9. Up Next: Creating Classes— Your Own Datatypes!
  10. Classes
    1. Defining Classes
      1. Class Attributes
        1. The dynamic attribute
        2. The intrinsic attribute
    2. Constructor Functions (Take 1)
    3. Properties
      1. Property Attributes (1/2)
      2. Property Attributes (2/2)
        1. Restricting property access with the private and public attributes
        2. Defining class properties with the static attribute
        3. Global variables versus class properties
        4. Subclasses and class properties
      3. Compile-Time Constant Expressions
      4. Enumerating Properties with for-in loops
    4. Methods
      1. Referring to the Current Object with the Keyword this
        1. Passing the current object to a method
        2. Managing parameter/property name conflicts
        3. Redundant use of the keyword this
      2. Method Attributes (1/2)
      3. Method Attributes (2/2)
        1. Controlling method access with the public and private attributes
        2. Defining class methods with the static attribute
      4. Accessor Methods
      5. Local Variables
      6. Nesting Functions in Methods
        1. Accessing the current object from a function nested in a method
      7. Getter and Setter Methods
        1. Simulating read-only properties
      8. Extra or Missing Arguments
    5. Constructor Functions (Take 2)
      1. Simulating Multiple Constructor Functions
      2. Using this in Constructor Functions
      3. Constructor Functions Versus Default Property Values
    6. Completing the Box Class
    7. Putting Theory into Practice
  11. Authoring an ActionScript 2.0 Class
    1. Class Authoring Quick Start
    2. Designing the ImageViewer Class
      1. From Functional Requirements to Code
    3. ImageViewer Implementation (Take 1)
    4. Using ImageViewer in a Movie
      1. Preloading the ImageViewer Class
    5. ImageViewer Implementation (Take 2)
      1. ImageViewer (Take 2), Design Summary
      2. ImageViewer Implementation (Take 2)
      3. Using ImageViewer (Take 2)
    6. ImageViewer Implementation (Take 3)
      1. Deleting a Class’s Resources
      2. The Final ImageViewer Code (1/2)
      3. The Final ImageViewer Code (2/2)
    7. Back to the Classroom
  12. Inheritance
    1. A Primer on Inheritance
      1. Class Method and Class Property Inheritance
    2. Subclasses as Subtypes
    3. An OOP Chat Example
    4. Overriding Methods and Properties
      1. Overriding Instance Methods
      2. Invoking an Overridden Instance Method
      3. Overriding Class Methods
      4. Overriding Properties
        1. The super keyword and overridden property access
      5. Member Access from Inherited, Overriding, and Overridden Instance Methods (1/3)
      6. Member Access from Inherited, Overriding, and Overridden Instance Methods (2/3)
      7. Member Access from Inherited, Overriding, and Overridden Instance Methods (3/3)
        1. Member access from an inherited instance method
        2. Member access from an overriding instance method
        3. Member access from an overridden method invoked via super
      8. Member Access from Inherited and Overridden Class Methods
      9. Best Practices for Overriding
    5. Constructor Functions in Subclasses
      1. Extraneous Superclass Constructor Invocation in Flash Player 6
    6. Subclassing Built-in Classes
      1. Built-in Classes that Store Function Libraries
    7. Augmenting Built-in Classes and Objects
    8. The Theory of Inheritance
      1. Why Inheritance?
      2. Polymorphism and Dynamic Binding
      3. Inheritance Versus Composition
        1. Is-A, Has-A, and Uses-A
        2. When to use composition over inheritance
        3. Using composition to shed an old habit
    9. Abstract and Final Classes Not Supported
    10. Let’s Try Inheritance
  13. Authoring an ActionScript 2.0 Subclass
    1. Extending ImageViewer’s Capabilities
    2. The ImageViewerDeluxe Skeleton
    3. Adding setPosition( ) and setSize( ) Methods
    4. Autosizing the Image Viewer
    5. Using ImageViewerDeluxe
    6. Moving Right Along
  14. Interfaces
    1. The Case for Interfaces
    2. Interfaces and Multidatatype Classes
    3. Interface Syntax and Use
      1. Interface Naming Conventions
      2. Interface Inheritance
      3. Marker Interfaces
    4. Multiple Type Inheritance with Interfaces
    5. Up Next, Packages
  15. Packages
    1. Package Syntax
      1. The import Statement
      2. Importing an Entire Package
      3. Package Naming Conventions
    2. Defining Packages
    3. Package Access and the Classpath
      1. Adding a New Directory to the Classpath
    4. Simulating Packages in ActionScript 1.0
    5. Just a Little More Theory
  16. Exceptions
    1. The Exception-Handling Cycle
    2. Handling Multiple Types of Exceptions
      1. Determining Exception Type Granularity (1/2)
      2. Determining Exception Type Granularity (2/2)
        1. Using a single custom exception type
        2. Using configurable debugging messages
        3. Multiple custom BoxDimensionException subclasses
    3. Exception Bubbling
      1. Uncaught Exceptions
    4. The finally Block
    5. Nested Exceptions
      1. A Nested Exception Bug
    6. Control Flow Changes in try/catch/finally
    7. Limitations of Exception Handling in ActionScript 2.0
      1. No Checked Exceptions
      2. No Built-in Exceptions
      3. Exception Performance Issues
    8. From Concepts to Code
  17. Part II
  18. An OOP Application Framework
    1. The Basic Directory Structure
    2. The Flash Document (.fla file)
    3. The Classes
    4. The Document Timeline
    5. The Exported Flash Movie (.swf file)
    6. Projects in Flash MX Professional 2004
    7. Let’s See It in Action!
  19. Using Components with ActionScript 2.0
    1. Currency Converter Application Overview
    2. Preparing the Flash Document
      1. Adding Components to the Document
      2. Starting the Application
    3. The CurrencyConverter Class
      1. Importing the Components’ Package
      2. CurrencyConverter Properties
      3. The main( ) method
      4. The Class Constructor
      5. Creating the User Interface
        1. The interface container
        2. The title Label component
        3. The instructions Label component
        4. The input TextInput component
        5. The currencyPicker ComboBox component
        6. The convertButton Button component
        7. The result TextArea component
      6. Converting Currency Based on User Input
      7. Exporting the Final Application
    4. Handling Component Events
    5. Components Complete
  20. MovieClip Subclasses
    1. The Duality of MovieClip Subclasses
    2. Avatar: A MovieClip Subclass Example
      1. The AvatarSymbol Movie Clip
      2. The Avatar Class
      3. Linking AvatarSymbol to the Avatar Class
      4. Creating Avatar Instances
      5. Initializing Avatar Instances
    3. Avatar: The Composition Version
    4. Issues with Nested Assets
      1. Properties and Methods of Nested Assets Initially Undefined
      2. Nested Assets Not Automatically Recognized by Compiler
    5. A Note on MovieClip Sub-subclasses
    6. Curiouser and Curiouser
  21. Distributing Class Libraries
    1. Sharing Class Source Files
      1. Loading Classes at Runtime
        1. Create the classes in the class library
        2. Create the class library .swf file
        3. Create the movie that loads the class library .swf file
        4. Create the exclusion XML file
        5. Try it out
    2. Sharing Classes Without Sharing Source Files
      1. Runtime Versus Compile Time
      2. Creating a No-Source Compile-time Class Library
        1. Create the classes in the class library
        2. Create the component icon
        3. Create the component class
        4. Create the component
        5. Distribute the component to developers
        6. Try it out
      3. Creating a No-Source Runtime Class Library
    3. Solving Real OOP Problems
  22. Part III
  23. Introduction to Design Patterns
    1. Bring on the Patterns
  24. The Observer Design Pattern
    1. Implementing Observer in ActionScript 2.0 (1/2)
    2. Implementing Observer in ActionScript 2.0 (2/2)
    3. Logger: A Complete Observer Example
      1. The LogMessage Class
      2. The OutputPanelView Class
      3. The TextFieldView Class
      4. The Logger Class (1/2)
      5. The Logger Class (2/2)
      6. Inheritance Misuse?
      7. Using the Logger Class
    4. Memory Management Issues with Observer
    5. Beyond Observer
  25. The Singleton Design Pattern
    1. Implementing Singleton in ActionScript 2.0
    2. The Singleton Pattern in the Logger Class
    3. Singleton Versus Class Methods and Class Properties
    4. A Warning Against Singletons as Globals
    5. On to User Interfaces
  26. The Model-View-Controller Design Pattern
    1. The General Architecture of MVC
      1. Communication in MVC
      2. Class Responsibilities in MVC
        1. Responsibilities of the model
        2. Responsibilities of the view
        3. Responsibilities of the controller
      3. What Creates the MVC Classes?
    2. A Generalized MVC Implementation
      1. The View Implementation
      2. The Controller Implementation
    3. An MVC Clock
      1. The ClockModel Class
      2. The ClockUpdate Class
      3. The ClockAnalogView and ClockDigitalView Classes (1/2)
      4. The ClockAnalogView and ClockDigitalView Classes (2/2)
      5. The ClockTools Class
      6. The ClockController Class
      7. Putting It All Together: The Clock Class
    4. Further Exploration
  27. The Delegation Event Model
    1. Structure and Participants
      1. The Event Source
      2. The Event Object
      3. The Event Listener
      4. Are Observer and Delegation Event Model Equivalent?
    2. The Flow of Logic
    3. Core Implementation
      1. The EventListenerList Class
      2. The EventObject Class
      3. The EventListener Interface
    4. NightSky: A Delegation Event Model Example
      1. The Event Source
      2. The EventListener Subinterface
      3. The EventObject Subclass
      4. The Event Listener Class
      5. The Overall Structure
      6. Randomizer, RandomizerListener, and RandomizerEvent
        1. Multiple event types from a single event source
      7. The NightSky Class
      8. Using NightSky in an Application
    5. Other Event Architectures in ActionScript
    6. From Some Place to Some OtherPlace
  28. Part IV
  29. ActionScript 2.0 Language QuickReference
    1. Global Properties
    2. Global Functions
      1. Accessibility Class
      2. Arguments Class
      3. Array Class
      4. Boolean Class
      5. Button Class
      6. Camera Class
      7. Color Class
      8. ContextMenu Class
      9. ContextMenuItem Class
      10. Date Class
      11. Function Class
      12. Key Class
      13. LoadVars Class
      14. LocalConnection Class
      15. Math Class
      16. Microphone Class
      17. Mouse Class
      18. MovieClip Class
      19. MovieClipLoader Class
      20. NetConnection Class
      21. NetStream Class
      22. Number Class
      23. Object Class
      24. PrintJob Class
      25. Selection Class
      26. SharedObject Class
      27. Sound Class
      28. Stage Class
      29. String Class
      30. System Class
      31. System.capabilities Class
      32. System.security Class
      33. TextField Class
      34. TextField.StyleSheet Class
      35. TextFormat Class
      36. TextSnapshot Class
      37. Video Class
      38. XML Class
      39. XMLNode Class
      40. XMLSocket Class
  30. Differences from ECMAScript Edition 4
  31. Index (1/5)
  32. Index (2/5)
  33. Index (3/5)
  34. Index (4/5)
  35. Index (5/5)

Product information

  • Title: Essential ActionScript 2.0
  • Author(s): Colin Moock
  • Release date: June 2004
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596006525