Foundation ActionScript for Flash 8

Book description

ActionScript is the native scripting language of Flash. ActionScript knowledge is essential within the world of Flash design and development, as Flash remains a leading tool for cutting-edge interactive design and development.

ActionScript is what gives Flash its power, but with that power comes a certain level of complexity, which can be intimidating. This beginners' book, significantly updated since the last edition, covers all of the basics of ActionScript using version 8 of Flash. The skills acquired by working through this book will enable you to move on to more advanced friends of ED books, such as Foundation PHP 5 for Flash, Foundation ActionScript Animation or Foundation XML for Flash.

This book contains all you need to understand and make use of ActionScript, and to have some fun while learning. The Foundation series teaching style is ideal if you're a non-programmer who wants to learn Flash programming quickly and thoroughly. The authors teach the basics, and provide an all-around proficiency in ActionScript, as well as Flash components within Flash 8. You'll gain the practical skills to build ActionScript based Flash projects, including making initial design decisions, structuring code, and testing. An ongoing case study means that by the end of the book, you'll have constructed a cutting-edge Flash site to showcase your newly learned skills.

Table of contents

  1. Copyright
  2. ABOUT THE AUTHORS
  3. ABOUT THE COVER IMAGE DESIGNER
  4. Introduction
    1. What you need to know
    2. FLAs for download
    3. The case study: Futuremedia
      1. Centering the Futuremedia site in the browser
    4. Layout conventions
    5. PCs and Macs
  5. 1. INTERACTIVE FLASH
    1. 1.1. Giving your movies instructions
    2. 1.2. Working with the Actions panel
    3. 1.3. Direct typing
    4. 1.4. Who are you talking to?
      1. 1.4.1. Controlling movie clips on the stage
    5. 1.5. Arguments
    6. 1.6. Listening to what your movies are telling you
      1. 1.6.1. Events in Flash
        1. 1.6.1.1. External events
        2. 1.6.1.2. Internal events
    7. 1.7. Introducing event handlers
      1. 1.7.1. Nesting spiders—argh!
      2. 1.7.2. Animating movie clips with ActionScript
    8. 1.8. Summary
  6. 2. MAKING PLANS
    1. 2.1. Defining the problem
      1. 2.1.1. Keep your ideas in a safer place than your head
      2. 2.1.2. Storyboarding
    2. 2.2. Building your ActionScript
      1. 2.2.1. Thinking from the top down
      2. 2.2.2. Thinking from the bottom up
        1. 2.2.2.1. Flowcharting
    3. 2.3. Book project: Introducing the Futuremedia site
      1. 2.3.1. Solving problem 1
      2. 2.3.2. Solving problem 2
      3. 2.3.3. Solving problems 3 and 4
      4. 2.3.4. Parting shots
    4. 2.4. Summary
  7. 3. MOVIES THAT REMEMBER
    1. 3.1. Introducing variables
      1. 3.1.1. Values and types
      2. 3.1.2. Creating variables and using them with literals and expressions
        1. 3.1.2.1. Naming variables
        2. 3.1.2.2. Creating variables
        3. 3.1.2.3. Using literal values
        4. 3.1.2.4. Using expressions
      3. 3.1.3. Input and output
      4. 3.1.4. Using string expressions
      5. 3.1.5. Working with numbers
        1. 3.1.5.1. Other uses for numeric expressions
      6. 3.1.6. Working with Boolean values
        1. 3.1.6.1. Logic operators
    2. 3.2. Arrays
      1. 3.2.1. Reasons for using arrays
        1. 3.2.1.1. Arrays let you store related information together
        2. 3.2.1.2. Arrays let you hold information in a specific order
        3. 3.2.1.3. Arrays let you index information
        4. 3.2.1.4. Arrays let you link information
      2. 3.2.2. Creating a new array
      3. 3.2.3. Typing an array
      4. 3.2.4. Using variable values as offsets
    3. 3.3. Book project: Starting the Futuremedia site design
      1. 3.3.1. What you're going to do
      2. 3.3.2. What you're going to learn
      3. 3.3.3. Choosing and setting the stage size
      4. 3.3.4. Setting up the timeline
      5. 3.3.5. Creating layout guides
      6. 3.3.6. Adding the position and status text
        1. 3.3.6.1. Choosing a font
        2. 3.3.6.2. Adding the text
        3. 3.3.6.3. Embedding the font
      7. 3.3.7. Parting shots
    4. 3.4. Summary
  8. 4. MOVIES THAT DECIDE FOR THEMSELVES
    1. 4.1. Decision making
      1. 4.1.1. Making decisions in ActionScript: The if action
      2. 4.1.2. Defining a decision
    2. 4.2. Alternative actions
      1. 4.2.1. Acting on alternatives: The else action
      2. 4.2.2. More than one alternative: The else if action
      3. 4.2.3. Handling lots of alternatives: The switch action
      4. 4.2.4. Switching without breaks
    3. 4.3. Organizing your code in the correct order
    4. 4.4. Summary
  9. 5. MORE POWER, LESS SCRIPT
    1. 5.1. Timeline loops
    2. 5.2. ActionScript loops
    3. 5.3. while loops
      1. 5.3.1. Useful things to do with while loops
      2. 5.3.2. for loops
        1. 5.3.2.1. init
        2. 5.3.2.2. condition
        3. 5.3.2.3. next
      3. 5.3.3. Some useful examples of for loops
        1. 5.3.3.1. Simple loop
        2. 5.3.3.2. Reverse loop
        3. 5.3.3.3. Two at a time
    4. 5.4. Looping through elements in an array
      1. 5.4.1. Applying an operation to all the elements in an array
      2. 5.4.2. Searching an array for a specific value
      3. 5.4.3. Cross-indexing a pair of arrays
    5. 5.5. Hangman
    6. 5.6. Book project: Creating the static graphics
      1. 5.6.1. Setting up the timeline layers for your graphics
      2. 5.6.2. Creating the back strip
      3. 5.6.3. Adding structure to the Library
      4. 5.6.4. Creating the frame cutout
      5. 5.6.5. Revealing the frame cutout and finishing the FLA
      6. 5.6.6. Parting shots
    7. 5.7. Summary
  10. 6. MOVIES THAT REMEMBER HOW TO DO THINGS
    1. 6.1. Breaking down a task
    2. 6.2. Bundling actions and running them afterward
      1. 6.2.1. Using anonymous and named functions
      2. 6.2.2. Using functions to hide evil math
    3. 6.3. Using functions to take care of repetitive jobs
    4. 6.4. Choosing which actions to bundle and where
      1. 6.4.1. Arguments and redundancy
      2. 6.4.2. Local variables and modular code
      3. 6.4.3. Returning values from a function
      4. 6.4.4. Typing functions
      5. 6.4.5. Running in circles
    5. 6.5. Nesting functions
      1. 6.5.1. Using nested functions
      2. 6.5.2. Using more function nesting to tidy up your script
    6. 6.6. Book project: Creating the dynamic graphics
    7. 6.7. Summary
  11. 7. OBJECTS AND CLASSES
    1. 7.1. Introducing objects and classes
      1. 7.1.1. Type and object-oriented programming
      2. 7.1.2. Classes, generalization, and abstraction
      3. 7.1.3. Seeing arrays in a new light
        1. 7.1.3.1. The Array constructor method
        2. 7.1.3.2. Other Array methods
        3. 7.1.3.3. Array properties
    2. 7.2. Creating classes and objects (instances) in Flash
      1. 7.2.1. Instances
      2. 7.2.2. The Object object
      3. 7.2.3. Viewing an object in Flash
      4. 7.2.4. Constructors
    3. 7.3. Objects, objects, everywhere . . .
      1. 7.3.1. Lurking objects
      2. 7.3.2. Making a show reel
    4. 7.4. Book project: Initializing the code
      1. 7.4.1. Getting yourself comfortable
      2. 7.4.2. Initializing the site variables
      3. 7.4.3. Telling ActionScript about the stage
        1. 7.4.3.1. Sanity check
      4. 7.4.4. Setting up your tricolor colors
        1. 7.4.4.1. Sanity check
    5. 7.5. Final words
    6. 7.6. Summary
  12. 8. OBJECTS ON THE STAGE
    1. 8.1. Movie clips and buttons as objects
      1. 8.1.1. Symbol types and behaviors
      2. 8.1.2. Two sides of the same object
    2. 8.2. Working with Library items
    3. 8.3. Let chaos reign
    4. 8.4. Bitmap caching
    5. 8.5. The other side of bitmap caching
      1. 8.5.1. Bitmap caching and RAM
      2. 8.5.2. Changing the appearance of a cached movie clip
      3. 8.5.3. When to use bitmap caching
    6. 8.6. Referencing different timelines with ActionScript
      1. 8.6.1. Different place, different variable
        1. 8.6.1.1. Locating variables from inside an event handler function
        2. 8.6.1.2. Reusing handler functions
    7. 8.7. The apply method
    8. 8.8. Global variables
    9. 8.9. Summary
  13. 9. REUSABLE CODE AND REALISTIC MOVEMENT
    1. 9.1. Breaking down big tasks into smaller ones
      1. 9.1.1. Black-box programming
    2. 9.2. Creating simple components
      1. 9.2.1. Creating a modular set of playback controls
      2. 9.2.2. Dark Valentine
    3. 9.3. Modular control of movie clips
      1. 9.3.1. How to simulate realistic movement
        1. 9.3.1.1. Motion with acceleration
    4. 9.4. Trailing the pointer (a mouse follower)
      1. 9.4.1. Understanding the inertial code
      2. 9.4.2. Fine-tuning the component
    5. 9.5. Function-based modular code
      1. 9.5.1. Swarming behavior
      2. 9.5.2. Taking the swarming effect forward
    6. 9.6. Creating tweens with ActionScript
      1. 9.6.1. Using import to access the Tween class
      2. 9.6.2. How to use the Tween constructor function
      3. 9.6.3. Understanding the transition types
    7. 9.7. Book project: Setting up the color transition
      1. 9.7.1. Making it modular
      2. 9.7.2. Sanity check #1
      3. 9.7.3. Sanity check #2
      4. 9.7.4. Running the FLA: The results
      5. 9.7.5. Parting shots
    8. 9.8. Summary
  14. 10. Games and Sprites
    1. 10.1. What is a sprite?
    2. 10.2. Control
      1. 10.2.1. External and internal data
    3. 10.3. Movement
    4. 10.4. Collision
      1. 10.4.1. Planning zapper
    5. 10.5. The game world (the main timeline)
      1. 10.5.1. gSCREEN_TOP, gSCREEN_BOTTOM, gSCREEN_RIGHT, and gSCREEN_LEFT
      2. 10.5.2. score
      3. 10.5.3. level, skill, and accel
      4. 10.5.4. speed
      5. 10.5.5. shipDead, fired, and gSHIP_HEIGHT
      6. 10.5.6. The timeline
    6. 10.6. The code
      1. 10.6.1. Global constants
      2. 10.6.2. The "start game" trigger
      3. 10.6.3. The player (the ship)
      4. 10.6.4. The SwarmAlien
        1. 10.6.4.1. alienSpawn()
        2. 10.6.4.2. onEnterFrame
        3. 10.6.4.3. alienBrain()
        4. 10.6.4.4. alienReincarnate()
      5. 10.6.5. The SwarmAlien code
      6. 10.6.6. The bullet
      7. 10.6.7. The debris of war
    7. 10.7. Book project: Navigation event handling
      1. 10.7.1. Sanity check #1
      2. 10.7.2. Adding the basic UI animation
        1. 10.7.2.1. navigate() and posTransition()
      3. 10.7.3. Adding typing
      4. 10.7.4. Sanity check #2
      5. 10.7.5. Creating a smooth transition
      6. 10.7.6. Parting shots
    8. 10.8. Summary
  15. 11. Drawing API
    1. 11.1. Turtle graphics
    2. 11.2. Drawing lines
    3. 11.3. Drawing curves
      1. 11.3.1. How the sketching code works
    4. 11.4. Filling shapes
    5. 11.5. Creating a kaleidoscope
      1. 11.5.1. Kaleidoscope math
      2. 11.5.2. Building the kaleidoscope engine
    6. 11.6. Book project: Color transition event handling and data
      1. 11.6.1. Wiring the colTransition() function
        1. 11.6.1.1. The game plan
        2. 11.6.1.2. Fading color
      2. 11.6.2. Coding the color transition
      3. 11.6.3. Finishing the text transition
      4. 11.6.4. Reviewing the code so far
      5. 11.6.5. Data-driven sites (and why you need to understand them)
        1. 11.6.5.1. Defining data for Futuremedia
      6. 11.6.6. Parting shots
    7. 11.7. Summary
  16. 12. ADDING SOUND TO FLASH
    1. 12.1. Choosing the right sound format
    2. 12.2. Using sound on a timeline
    3. 12.3. Using the ActionScript Sound class
      1. 12.3.1. Playing sounds from ActionScript
        1. 12.3.1.1. Attaching sounds to a sound instance
        2. 12.3.1.2. Starting and stopping sounds
        3. 12.3.1.3. Creating dynamic soundtracks
        4. 12.3.1.4. Using ActionScript to control volume and balance
    4. 12.4. Dealing with large sound files
      1. 12.4.1. Using compression to reduce download times
      2. 12.4.2. Loading sound from external files
    5. 12.5. Silence can also be golden
    6. 12.6. Summary
  17. 13. LOADING DYNAMIC DATA WITH XML
    1. 13.1. XML 101
      1. 13.1.1. How an XML document is structured
      2. 13.1.2. Using the right version and encoding
        1. 13.1.2.1. Using non-English text with XML in Flash
        2. 13.1.2.2. Saving XML files in UTF-8
          1. 13.1.2.2.1. Windows Notepad
          2. 13.1.2.2.2. TextEdit (Mac OS X)
          3. 13.1.2.2.3. Dreamweaver
          4. 13.1.2.2.4. Dedicated XML editors
      3. 13.1.3. How tags are used in XML
      4. 13.1.4. Checking that your document is well formed
    2. 13.2. Loading XML into Flash
    3. 13.3. Book project: Controlling structure and content with XML
      1. 13.3.1. Building the basic XML structure
      2. 13.3.2. Loading the XML data into Flash
      3. 13.3.3. Creating the Futuremedia site's data structure
        1. 13.3.3.1. How the page array is structured
      4. 13.3.4. Populating the actual data values
        1. 13.3.4.1. Moving to the next level
      5. 13.3.5. Sanity check
    4. 13.4. Summary
  18. 14. FINISHING THE FUTUREMEDIA CASE STUDY
    1. 14.1. Getting the data into the user interface
      1. 14.1.1. Amending the way events are handled
      2. 14.1.2. Reading content pages
    2. 14.2. Adding the backward path
      1. 14.2.1. Making sure the UI knows where it needs to return
        1. 14.2.1.1. How the buildIcon() function works
    3. 14.3. Tidying up the user interface
      1. 14.3.1. A great big sanity check
      2. 14.3.2. Adding the status text messages
      3. 14.3.3. Adding a preloader
      4. 14.3.4. Loading your own content into the site
      5. 14.3.5. Parting shots
    4. 14.4. Summary
  19. 15. Advanced ActionScript: Components and Classes
    1. 15.1. Flash version 2 components
      1. 15.1.1. Getting more out of components with ActionScript
      2. 15.1.2. Components and event handling
        1. 15.1.2.1. How event listeners work
        2. 15.1.2.2. Adding an event listener
        3. 15.1.2.3. Understanding the advantages of event listeners
      3. 15.1.3. Commonly used components
        1. 15.1.3.1. Radio buttons
        2. 15.1.3.2. Check boxes
        3. 15.1.3.3. Combo boxes (drop-down menus)
      4. 15.1.4. Using code hints with components
      5. 15.1.5. Loading components at runtime
      6. 15.1.6. Removing components
      7. 15.1.7. Removing listeners
    2. 15.2. ActionScript and OOP
      1. 15.2.1. The future road map for ActionScript
      2. 15.2.2. Is OOP for me?
      3. 15.2.3. How class-based coding works
      4. 15.2.4. Extending classes
      5. 15.2.5. Extending a built-in class
      6. 15.2.6. Storing classes in a central location
    3. 15.3. Final thoughts

Product information

  • Title: Foundation ActionScript for Flash 8
  • Author(s):
  • Release date: June 2007
  • Publisher(s): Apress
  • ISBN: 9781590596180