
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Further ActionScript Concepts
|
19
less work than the nonfunction version of our code shown earlier. Enclosing reus-
able code within functions save us time and reduces the number of lines of code
needed. It also makes our code much more legible and modular. Someone reading
the code can probably guess what the area( ) function does, based solely on its name.
Don’t fret if you have questions about this function example; we’ll learn more about
functions in Chapter 9. For now, just remember that functions give us an extremely
powerful way to create complex systems. Functions help us reuse our code and pack-
age its functionality, extending the limits of what is practical to build.
Built-in functions
Notice that functions take arguments just as the trace() command does. Invoking
the function area(4, 5); looks very much the same as issuing the trace() command
such as trace (x); except that the area( ) function requires two arguments, which are
separated by commas, whereas the trace() command requires a single argument. The
similarity is not a coincidence. As we learned earlier, many Actions, including the
trace() Action, are actually functions. But they are a special type of function that is
built into ActionScript (as opposed to user-defined functions, like our area() func-
tion). It is,