
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
182
Chapter 9
CHAPTER 9
Functions
I’m almost giddy to tell you about functions because they’re such a powerful part of
ActionScript. A function is simply a chunk of code that can be reused throughout a
program. Not only do functions lend enormous flexibility and convenience to our
scripts, they also give us control over Flash movie elements. I can hardly imagine
programming without functions—they ease performing common operations, from
sorting words to calculating the distance between two movie clips. We’ll introduce
functions in this chapter before learning how to create complex, powerful programs
using functions with objects in Chapter 12.
We’ll focus first on the simplest functions to understand—custom functions—the
functions we create in our scripts, as distinguished from the built-in functions pro-
vided with ActionScript.
The ECMA-262 specification refers to custom functions as program
functions and built-in functions as internal functions. We use the collo-
quial name in both cases rather than the formal specification’s termi-
nology.
By learning to create your own functions, you’ll become familiar with these funda-
mentals:
Function declaration or function definition
Creating functions for future use in our scripts.
Function invocation
Causing functions to execute. In other words,