ActionScript 3.0 Cookbook

Book description

Well before Ajax and Microsoft's Windows Presentation Foundation hit the scene, Macromedia offered the first method for building web pages with the responsiveness and functionality of desktop programs with its Flash-based "Rich Internet Applications". Now, new owner Adobe is taking Flash and its powerful capabilities beyond the Web and making it a full-fledged development environment.

Rather than focus on theory, the ActionScript 3.0 Cookbook concentrates on the practical application of ActionScript, with more than 300 solutions you can use to solve a wide range of common coding dilemmas. You'll find recipes that show you how to:

  • Detect the user's Flash Player version or their operating system
  • Build custom classes
  • Format dates and currency types
  • Work with strings
  • Build user interface components
  • Work with audio and video
  • Make remote procedure calls using Flash Remoting and web services
  • Load, send, and search XML data
  • And much, much more ...

Each code recipe presents the Problem, Solution, and Discussion of how you can use it in other ways or personalize it for your own needs, and why it works. You can quickly locate the recipe that most closely matches your situation and get the solution without reading the whole book to understand the underlying code. Solutions progress from short recipes for small problems to more complex scripts for thornier riddles, and the discussions offer a deeper analysis for resolving similar issues in the future, along with possible design choices and ramifications. You'll even learn how to link modular ActionScript pieces together to create rock-solid solutions for Flex 2 and Flash applications.

When you're not sure how ActionScript 3.0 works or how to approach a specific programming dilemma, you can simply pick up the book, flip to the relevant recipe(s), and quickly find the solution you're looking for.

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.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. What’s Not in This Book
    2. Compatibility
    3. Flash Platform Naming Conventions
    4. The Code
    5. Audience for This Book
    6. How This Book Is Organized
    7. How to Use This Book
    8. Conventions Used in This Book
    9. Using Code Examples
    10. O’Reilly Cookbooks
    11. Safari® Enabled
    12. How to Contact Us
    13. About the Tech Reviewers
    14. Acknowledgments
  3. 1. ActionScript Basics
    1. Introduction
    2. Creating an ActionScript Project
    3. Customizing the Properties of an Application
    4. Where to Place ActionScript Code
    5. How to Trace a Message
    6. Handling Events
    7. Responding to Mouse and Key Events
    8. Using Mathematical Operators
    9. Checking Equality or Comparing Values
    10. Performing Actions Conditionally
    11. Performing Complex Conditional Testing
    12. Repeating an Operation Many Times
    13. Repeating a Task over Time
    14. Creating Reusable Code
    15. Generalizing a Method to Enhance Reusability
    16. Exiting a Method
    17. Obtaining the Result of a Method
    18. Handling Errors
  4. 2. Custom Classes
    1. Introduction
    2. Creating a Custom Class
    3. Determining Where to Save a Class
    4. Creating Properties That Behave As Methods
    5. Creating Static Methods and Properties
    6. Creating Subclasses
    7. Implementing Subclass Versions of Superclass Methods
    8. Creating Constants
    9. Dispatching Events
  5. 3. Runtime Environment
    1. Introduction
    2. Detecting the Player Version
    3. Detecting the Operating System
    4. Checking the Player Type
    5. Checking the System Language
    6. Detecting Display Settings
    7. Scaling the Movie
    8. Changing the Alignment
    9. Hiding the Flash Player’s Menu Items
    10. Detecting the Device’s Audio Capabilities
    11. Detecting the Device’s Video Capabilities
    12. Prompting the User to Change Player Settings
    13. Dealing with System Security
  6. 4. Numbers and Math
    1. Introduction
    2. Representing Numbers in Different Bases
    3. Converting Between Different Number Systems
    4. Rounding Numbers
    5. Inserting Leading or Trailing Zeros or Spaces
    6. Formatting Numbers for Display Without a Mask
    7. Formatting Currency Amounts
    8. Generating a Random Number
    9. Simulating a Coin Toss
    10. Simulating Dice
    11. Simulating Playing Cards
    12. Generating a Unique Number
    13. Converting Angle Measurements
    14. Calculating the Distance Between Two Points
    15. Determining Points Along a Circle
    16. Converting Between Units of Measurement
  7. 5. Arrays
    1. Introduction
    2. Adding Elements to the Start or End of an Array
    3. Looping Through an Array
    4. Searching for Matching Elements in an Array
    5. Removing Elements
    6. Inserting Elements in the Middle of an Array
    7. Converting a String to an Array
    8. Converting an Array to a String
    9. Creating a Separate Copy of an Array
    10. Storing Complex or Multidimensional Data
    11. Sorting or Reversing an Array
    12. Implementing a Custom Sort
    13. Randomizing the Elements of an Array
    14. Getting the Minimum or Maximum Element
    15. Comparing Arrays
    16. Creating an Associative Array
    17. Reading Elements of an Associative Array
  8. 6. Display List
    1. Introduction
    2. Adding an Item to the Display List
    3. Removing an Item from the Display List
    4. Moving Objects Forward and Backward
    5. Creating Custom Visual Classes
    6. Creating Simple Buttons
    7. Loading External Images at Runtime
    8. Loading and Interacting with External Movies
    9. Creating Mouse Interactions
    10. Dragging and Dropping Objects with the Mouse
  9. 7. Drawing and Masking
    1. Introduction
    2. Setting a Line Style
    3. Setting Gradient Line Styles
    4. Drawing a Line
    5. Drawing a Curve
    6. Drawing an Arc
    7. Drawing a Rectangle
    8. Drawing a Circle
    9. Drawing an Ellipse
    10. Drawing a Triangle
    11. Drawing Regular Polygons
    12. Drawing a Star
    13. Filling a Shape with a Solid or Translucent Color
    14. Filling a Shape with a Gradient
    15. Filling a Shape with a Bitmap
    16. Scripting Masks
  10. 8. Bitmaps
    1. Introduction
    2. Creating a BitmapData Object
    3. Adding a Bitmap to the Display List
    4. Drawing a Display Object to a Bitmap
    5. Loading an External Image into a Bitmap
    6. Manipulating Pixels
    7. Creating Rectangular Fills
    8. Creating a Flood Fill
    9. Copying Pixels
    10. Copying Channels
    11. Creating Noise
    12. Creating Perlin Noise
    13. Using Threshold
    14. Applying a Filter to a Bitmap
    15. Dissolving Between Two Bitmaps
    16. Scrolling a Bitmap
  11. 9. Text
    1. Introduction
    2. Creating an Outline Around a Text Field
    3. Creating a Background for a Text Field
    4. Making a User Input Field
    5. Making a Password Input Field
    6. Filtering Text Input
    7. Setting a Field’s Maximum Length
    8. Displaying Text
    9. Displaying HTML-Formatted Text
    10. Condensing Whitespace
    11. Sizing Text Fields to Fit Contents
    12. Scrolling Text Programmatically
    13. Responding to Scroll Events
    14. Formatting Text
    15. Formatting User-Input Text
    16. Formatting a Portion of Existing Text
    17. Setting a Text Field’s Font
    18. Embedding Fonts
    19. Creating Text that Can Be Rotated
    20. Displaying Unicode Text
    21. Assigning Focus to a Text Field
    22. Selecting Text with ActionScript
    23. Setting the Insertion Point in a Text Field
    24. Responding When Text Is Selected or Deselected
    25. Responding to User Text Entry
    26. Adding a Hyperlink to Text
    27. Calling ActionScript from Hyperlinks
    28. Working with Advanced Text Layout
    29. Applying Advanced Anti-Aliasing
    30. Replacing Text
    31. Retrieving a List of System Fonts
  12. 10. Filters and Transforms
    1. Introduction
    2. Applying Color Changes
    3. Applying Color Tints
    4. Resetting Color
    5. Shearing
    6. Applying Basic Filters
    7. Applying Advanced Filter Effects (Emboss, etc.)
    8. Embossing
    9. Detecting Edges
    10. Sharpening
    11. Making a Digital Negative
    12. Applying Grayscale
    13. Changing Saturation
    14. Changing Brightness
    15. Changing Contrast
  13. 11. Programmatic Animation
    1. Introduction
    2. Moving an Object
    3. Moving an Object in a Specific Direction
    4. Easing
    5. Acceleration
    6. Springs
    7. Using Trigonometry
    8. Applying Animation Techniques to Other Properties
  14. 12. Strings
    1. Introduction
    2. Joining Strings
    3. Using Quotes and Apostrophes in Strings
    4. Inserting Special Whitespace Characters
    5. Searching for a Substring
    6. Extracting a Substring
    7. Parsing a String into Words
    8. Removing and Replacing Characters and Words
    9. Retrieving One Character at a Time
    10. Converting Case
    11. Trimming Whitespace
    12. Reversing a String by Word or by Character
    13. Converting Between Strings and Unicode or ASCII
  15. 13. Regular Expressions
    1. Introduction
    2. Understanding Regular Expression Patterns
    3. Testing Regular Expressions
    4. Looking for Pattern Matches
    5. Removing and Replacing Characters and Words Using Patterns
    6. Creating a Nongreedy Pattern
    7. Validating User Input with Common Patterns
  16. 14. Dates and Times
    1. Introduction
    2. Finding the Current Date and Time
    3. Retrieving the Date Values
    4. Retrieving the Day or Month Name
    5. Formatting the Date and Time
    6. Formatting Seconds or Milliseconds as Minutes and Seconds
    7. Converting Between DMYHMSM and Epoch Milliseconds
    8. Using Timers
    9. Calculating Elapsed Time or Intervals Between Dates
    10. Parsing a Date from a String
  17. 15. Programming Sound
    1. Introduction
    2. Creating a Sound Object and Loading a Sound
    3. Starting and Stopping a Sound
    4. Setting the Buffer for a Sound
    5. Offsetting the Start of a Sound
    6. Playing a Sound Multiple Times (Looping)
    7. Getting the Size of a Sound File
    8. Reading the ID3 Tag of a Sound File
    9. Find Out When a Sound Finishes Playing
    10. Tracking the Progress of a Playing Sound
    11. Pausing and Restarting a Sound
    12. Reading the Level of a Sound
    13. Stopping All Sounds
    14. Reading the Sound Spectrum
    15. Changing the Volume or Pan of a Sound
    16. Creating a Sound Application
  18. 16. Video
    1. Introduction
    2. Loading and Playing Back Video
    3. Controlling Video Sound
    4. Reading Playback Time
    5. Reading Video Duration
    6. Controlling Playback Time
    7. Scaling Video
    8. Managing and Monitoring Buffering and Loading
    9. Listening for Cue Points
    10. Applying Filters to Video
    11. Pausing and Resuming Video
    12. Stopping Video
    13. Scrubbing Video
    14. Clearing the Video Display
    15. Determining User Bandwidth
  19. 17. Storing Persistent Data
    1. Introduction
    2. Creating and Opening a Local Shared Object
    3. Writing Data to a Shared Object
    4. Saving a Local Shared Object
    5. Reading Data from a Shared Object
    6. Removing Data from a Shared Object
    7. Serializing Custom Classes
    8. Sharing Data Between Flash Applications
    9. Controlling the Size of Local Shared Objects
  20. 18. Communicating with Other Movies
    1. Introduction
    2. Creating Local Connections
    3. Sending Data
    4. Validating Receipt of Communication over Local Connections
    5. Accepting Local Communications from Other Domains
  21. 19. Sending and Loading Data
    1. Introduction
    2. Loading Variables from a Text File
    3. Loading Variables from a Server-Side Script
    4. Loading a Block of Text (Including HTML and XML)
    5. Checking Load Progress
    6. Accessing Data Being Downloaded
    7. Sending Data to a Server-Side Script
    8. Sending Variables and Handling a Returned Result
  22. 20. XML
    1. Introduction
    2. Understanding XML Structure (Reading and Writing XML)
    3. Creating an XML Object
    4. Adding Elements to an XML Object
    5. Adding Text Nodes to an XML Object
    6. Adding Attributes to an XML Element
    7. Reading Elements in an XML Tree
    8. Finding Elements by Name
    9. Reading Text Nodes and Their Values
    10. Reading an Element’s Attributes
    11. Removing Elements, Text Nodes, and Attributes
    12. Loading XML
    13. Loading XML from Different Domains
    14. Sending XML
    15. Searching XML
    16. Using HTML and Special Characters in XML
  23. 21. Web Services and Flash Remoting
    1. Introduction
    2. Calling Web Services Methods
    3. Handling Web Services Responses
    4. Handling Web Services Errors
    5. Calling Flash Remoting Methods
    6. Handling Flash Remoting Responses
  24. 22. Building Integrated Applications
    1. Introduction
    2. Calling JavaScript Functions
    3. Calling ActionScript Functions
    4. Passing Parameters from HTML
  25. 23. File Management
    1. Introduction
    2. Downloading Files
    3. Detecting When a User Selects a File to Upload
    4. Monitoring Download Progress
    5. Browsing for Files
    6. Filtering Files That Display in the Browser Window
    7. Detecting When the User Has Selected a File to Upload
    8. Uploading Files
    9. Monitoring File Upload Progress
  26. 24. Socket Programming
    1. Introduction
    2. Connecting to a Socket Server
    3. Sending Data
    4. Receiving Data
    5. Handshaking with a Socket Server
    6. Disconnecting from a Socket Server
    7. Handling Socket Errors
  27. 1. Unicode Escape Sequences for Latin 1 Characters
  28. Index
  29. About the Authors
  30. Copyright

Product information

  • Title: ActionScript 3.0 Cookbook
  • Author(s): Joey Lott, Darron Schall, Keith Peters
  • Release date: October 2006
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596526955