Learning ActionScript 3.0, 2nd Edition

Book description

If you're new to ActionScript 3.0, or want to enhance your skill set, this bestselling book is the ideal guide. Designers, developers, and programmers alike will find Learning ActionScript 3.0 invaluable for navigating ActionScript 3.0's learning curve. You'll learn the language by getting a clear look at essential topics such as logic, event handling, displaying content, classes, and much more.

Updated for Flash Professional CS5, this revised and expanded edition delivers hands-on exercises and full-color code samples to help you increase your abilities as you progress through the book. Topics are introduced with basic syntax and class-based examples, so you can set your own pace for learning object-oriented programming.

  • Harness the power and performance of ActionScript 3.0
  • Control sound and video, including new access to microphone data
  • Create art with code by drawing vectors and pixels at runtime
  • Manipulate text with unprecedented typographic control
  • Animate graphics, create particle systems, and apply simple physics
  • Avoid common coding mistakes and reuse code for improved productivity
  • Load SWF, image, text, HTML, CSS, and XML file formats, and more
Authors Rich Shupe and Zevan Rosser draw on their experience as Flash developers and instructors to give you a solid ActionScript foundation, revealing ways you can use code for practical, everyday projects.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Who This Book Is For
      1. Push Yourself
      2. ActionScript Editors
    2. How This Book Is Organized
    3. What Is—and Isn’t—In This Book
      1. What’s In
      2. What’s Not
    4. Companion Website
    5. Typographical Conventions Used In This Book
    6. Using Code Examples
    7. We’d Like To Hear From You
    8. Acknowledgments
    9. About the Authors
    10. Colophon
  3. I. Getting Started
    1. 1. What Is ActionScript?
      1. What’s New in ActionScript 3.0?
      2. The Flash Platform
      3. Procedural Versus Object-Oriented Programming
      4. The Document Class
      5. Legacy Code Compatibility
      6. Hello World
        1. Timeline Example
        2. Document Class Example
        3. Success
      7. What’s Next?
    2. 2. Core Language Fundamentals
      1. Jump Right In
      2. Miscellaneous Basics
      3. Variables and Data Types
        1. Casting
        2. Strict Mode
      4. Operators
        1. Arithmetic Operator Precedence
      5. Conditionals
        1. if
        2. Logical Operator Precedence
        3. switch
      6. Loops
        1. for Loop
        2. while Loop
        3. A Loop Caveat
      7. Arrays
      8. Vectors
      9. Functions
        1. Local Variables
        2. Parameters and Arguments
        3. Returning a Value from a Function
      10. Custom Objects
        1. Objects and Associative Arrays
      11. this and parent
      12. Absolute Versus Relative Addresses
      13. Put It All Together
      14. What’s Next?
  4. II. Graphics and Interaction
    1. 3. Properties, Methods, and Events
      1. Jump Right In
      2. Properties
      3. Events
        1. Using Event Listeners
        2. Using Mouse Events to Control Properties
      4. Methods
        1. Using Keyboard Events to Call Methods
      5. Event Propagation
      6. Frame and Timer Events
        1. Frame Events
        2. Timer Events
      7. Removing Event Listeners
      8. What’s Next?
    2. 4. The Display List
      1. Jump Right In
      2. The Sum of Its Parts
        1. Display List Classes
        2. Displaying the Display List
          1. The showChildren() function in action
      3. Adding and Removing Children
        1. Using addChild()
        2. Adding Custom Symbol Instances to the Display List
        3. Using addChildAt()
        4. Removing Objects from the Display List and from Memory
          1. Removing objects from memory
      4. Managing Object Names, Positions, and Data Types
        1. Finding Children by Position and by Name
        2. Clarifying or Changing the Data Type of a Display Object
      5. Changing the Display List Hierarchy
        1. Depth Management
        2. Reparenting Children
      6. A Dynamic Navigation Bar
      7. What’s Next?
    3. 5. Timeline Control
      1. Jump Right In
      2. Playhead Movement
      3. Frame Labels
        1. New Timeline ActionScript
      4. Frame Rate
      5. A Simple Site or Application Structure
      6. What’s Next?
    4. 6. OOP
      1. Classes
        1. Custom Class Review
        2. Classpaths
          1. Note to Flash Professional CS5 users
      2. Inheritance
        1. Symbol Base Classes
        2. Can You Figure Out Why?
        3. A More Traditional Look at Inheritance
          1. Vehicle class
          2. Simple example
          3. Car class
          4. Truck class
          5. Document class and revised FLA
        4. Accessing the Stage in a Class
      3. Composition
        1.  
          1. Car class
          2. Truck class
          3. New Tires class
          4. Document class
      4. Encapsulation
        1.  
          1. Getters and setters
          2. Vehicle class
          3. Car class
          4. Truck class
          5. Tires class
          6. Document class
      5. Polymorphism
        1.  
          1. Polymorphism and inheritance
          2. Vehicle class
          3. Car class
          4. Truck class
          5. Tires class and Document class
          6. Polymorphism and interfaces
          7. Simple example
          8. Adding a sound system to your vehicles through composition
      6. Navigation Bar Revisited
        1.  
          1. Document class
          2. NavigationBar
          3. MenuButtonMain
      7. What’s Next?
    5. 7. Motion
      1. Basic Movement
        1. Velocity
        2. Acceleration
        3. Easing
      2. Simple Physics
        1. Gravity
        2. Friction
        3. Elasticity
      3. A Basic Particle System
        1.  
          1. The particle
          2. The system
          3. The FLA file
      4. Simple Collision Detection
        1. Collision with Objects
        2. Collision with Points
        3. Collision with Stage Boundaries
      5. Geometry and Trigonometry
        1. Movement Along an Angle
        2. Distance
        3. More Particles: Collision and Distance
        4. Circular Movement
        5. A Circular Navigation System
        6. Rotation Toward an Object
          1. Creating a grid using modulus
      6. Programmatic Tweening
        1. Adobe’s Tween Class
        2. GreenSock’s TweenLite
          1. Creating a simple banner using TweenLite
        3. Reproducing Timeline Tweens with ActionScript
      7. What’s Next?
    6. 8. Drawing with Vectors
      1. The Graphics Class
        1. Drawing Lines
        2. Drawing Curves
        3. Adding Solid Fills
        4. Drawing Shapes
        5. Using Gradient Fills and Lines
          1. Gradient fills
          2. Gradient line styles
        6. Using Bitmap Fills and Lines
          1. Bitmap fills
          2. Bitmap line styles
        7. Simulating the Pencil Tool
        8. Drawing Complex Shapes with drawPath()
      2. The Geometry Package
        1. Creating Points
        2. Creating Rectangles
        3. Using Matrices
          1. Skewing with matrices
          2. Calculating changes in points after transformations
          3. Manipulating gradient fills and line styles
          4. Adjusting gradient line styles
          5. Adjusting bitmap line styles
        4. Gradient Spread Method
      3. 9-Slice Scaling
      4. Applied Examples
        1. Starting a Color Picker
        2. A Custom Button Class
      5. What’s Next?
    7. 9. Drawing with Pixels
      1. Bitmap Caching
        1. Soft-Edged Masks
      2. The BitmapData Class
        1. Creating Opaque Bitmaps
        2. Creating Bitmaps with Transparency
        3. Using a Bitmap from the Library
        4. Copying Pixels
        5. Drawing into a Bitmap
      3. Blend Modes
        1. ActionScript Compositing Blend Modes
          1. Layer
          2. Alpha and Erase
        2. Using Blend Modes with BitmapData Instances
      4. Bitmap Filters
        1. Basic Filters
          1. Creating dynamic button art with the DropShadowFilter
          2. Using the BlurFilter to create an airbrush
        2. Advanced Filters
          1. Convolution filter
          2. Perlin noise and displacement map
          3. Perlin noise
          4. Displacement map
          5. Animating the effect
      5. Color Effects
        1. The ColorTransform Class
        2. The ColorMatrixFilter Class
        3. The Color Class
      6. Image Encoding and Saving
        1. Saving JPG Images
      7. Adding Functionality to Your Color Picker
        1. Getting and Setting Pixels
          1. getPixel()
          2. Using the picker with setPixel()
        2. Expanding Your Paint Program
      8. What’s Next?
  5. III. Text
    1. 10. Text
      1. Creating Text Fields
      2. Setting Text Field Attributes
        1. Dynamic Text Fields
        2. Input Text Fields
      3. Selecting Text
      4. Formatting Text
        1.  
          1. Establishing a format for new text
          2. Applying a format to existing text
          3. Adding text after using setTextFormat()
        2. Tab Stops
        3. Using Embedded Fonts
          1. Flash Professional CS3 and CS4
          2. Flash Professional CS5
          3. ActionScript
        4. Using Custom Anti-Aliasing
      5. Formatting with HTML and CSS
        1. Hypertext Markup Language (HTML)
        2. CSS
          1. Escaping quotation marks
      6. Triggering ActionScript from HTML Links
      7. Loading HTML and CSS
      8. Text Layout Framework
        1.  
          1. Rotating device fonts
          2. Improved typographic controls
          3. Columnar layout
          4. Flowing text across multiple containers
          5. Distributing SWFs that use TLF
      9. What’s Next?
  6. IV. Sound and Video
    1. 11. Sound
      1. ActionScript Sound Architecture
      2. Internal and External Sounds
        1. Working with Sounds in Your Library
        2. Loading External Sounds
      3. Playing, Stopping, and Pausing Sounds
        1. Playing a Sound
        2. Stopping a Sound
        3. Pausing Sounds and Resuming Playback
        4. Applying the Syntax
      4. Buffering Sounds
      5. Changing Sound Volume and Pan
      6. Reading ID3 Metadata from MP3 Sounds
      7. Visualizing Sound Data
        1. Amplitude
          1. Adding peak meters to the sound player
        2. Sound Spectrum Data
          1. Storing and retrieving sound spectrum data
          2. Drawing a waveform or frequency spectrum
          3. The Waveform class
        3. Adding the Waveform Visualization to Our Sound Player
      8. Visualizing Microphone Input
        1. Activity Level
        2. SampleDataEvent
      9. Recording, Playing, and Saving Microphone Input
        1. RecordMicrophone Class
          1. Recording microphone input at runtime
          2. Writing sound data dynamically at runtime
          3. Stopping playback
        2. RecordMicrophone_Example Class
      10. What’s Next?
    2. 12. Video
      1. Encoding
        1. Formats
        2. Presets
        3. Customizing Settings
        4. Starting the Queue
      2. Components
        1. Working with the FLVPlayback Component
          1. Scripting the component
          2. Skinning the component
      3. Full-Screen Video
      4. Captions
        1. Using the FLVPlaybackCaptioning Component
        2. Creating Captions with Timed Text
        3. Providing Captions in Multiple Languages
      5. Writing Your Own Player
        1. Scripting Buttons to Control the FLVPlayback Component
        2. A Code-Only Solution
          1. The main video class
          2. The document class
      6. What’s Next?
  7. V. Input/Output
    1. 13. Loading Assets
      1. Loading SWFs and Images
        1. Loading SWFs
        2. Loading Images
        3. Writing a Multiuse SWF and Image Loading Class
        4. Writing the CustomLoader Class
        5. Using the CustomLoader Class
          1. Loading SWFs
          2. Loading images
      2. Loading Data
        1. Loading Text
        2. Loading Variables
        3. Loading Binary Data
        4. Writing a Multiuse Data Loading Class
        5. Writing the CustomURLLoader Class
        6. Using the CustomURLLoader Class
          1. Loading text
          2. Loading variables
          3. Loading binary data
      3. Communicating with Loaded SWFs
        1.  
          1. The child SWF
          2. The parent SWF
      4. Additional Online Resources
        1. Loading SWFs with TLF Assets
        2. GreenSock’s LoaderMax
      5. What’s Next?
    2. 14. XML
      1. Understanding XML Structure
        1. White Space
        2. Declarations
        3. Comments and Processing Instructions
        4. Entities and the CDATA Tag
      2. Creating an XML Object
      3. Using Variables in XML
      4. Reading XML
        1. Element and Text Nodes, and the XMLList Class
          1. Text nodes and strings
          2. Element nodes and the power of XMLList
          3. Using the descendant accessor operator and wildcards
        2. Using Attributes
          1. Coping with element node names that are incompatible with ActionScript
        3. Finding Elements by Content
          1. A limitation when filtering by attribute
      5. Writing XML
      6. Deleting XML
      7. Loading External XML Documents
      8. Sending to and Loading from a Server
        1. Send and Load
          1. The client source
          2. The server source
      9. An XML-Based Navigation System
        1. The Directory Structure and Source Files
        2. The Library of the FLA
        3. The XML and Classes
          1. XML
          2. LAS3Main (document class)
          3. NavigationBarXML
          4. MenuButtonMain
          5. MenuButtonSub
          6. Tying it all together
      10. What’s Next?
  8. Index
  9. About the Authors
  10. Copyright

Product information

  • Title: Learning ActionScript 3.0, 2nd Edition
  • Author(s): Zevan Rosser, Rich Shupe
  • Release date: October 2010
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449390174