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 provided with ActionScript.
|
By learning to create your own functions, you'll become familiar with these fundamentals:
Creating functions for future use in our scripts.
Causing functions to execute. In other words, running the code in a function. Also known as calling a function.
Providing functions with data to manipulate upon invocation.
Ending the execution of a function and, optionally, returning a result.
Determining the availability and life span of a function, and the accessibility of variables referenced in a function body.
Let's get to it!