Although we've seen how to create user-defined functions, let's not forget that ActionScript comes with a bevy of built-in functions (akin to verbs in our language analogy). We've already seen some built-in functions that allow us to manipulate data. We've also touched on functions that control the Flash movie and the user environment.
For example, to manipulate the playhead of a movie clip, we can call the gotoAndPlay( ) function with a frame number as a parameter:
gotoAndPlay(5);
If you are a new programmer, you may be experiencing an epiphany. I hope you have noticed that you invoke built-in functions using the function-call operator (the parentheses) and an argument list (the value 5 in this case) just like our custom user-defined functions! Built-in functions, such as gotoAndPlay( ), are used just like the functions we've been declaring ourselves. Custom functions typically do something that a built-in ActionScript function doesn't already offer. Like any custom function, each built-in function has a name, zero or more optional or required arguments, and a return value (although sometimes the value is undefined).
Even though Flash has long referred to gotoAndPlay as an "Action," we now see it in its true form, as a built-in function. In Chapter 6, you learned that some Flash Actions are statements and some are functions. Now that you've studied both thoroughly, you'll be able to tell which are which.
By understanding certain Actions as functions, you'll have an easier time remembering and using their syntax. For example, to load a movie into the Flash Player we need to know that a loadMovie( ) function exists and what parameters it expects. After a quick jaunt over to the Language Reference, we find the info and can easily put together a statement like this:
loadMovie("myMovie.swf", "_level1");
This will be easy stuff once you've become comfortable with using functions.
ActionScript's built-in functions are many and varied. They give us control over the elements of a movie, empowering us to examine and change everything from the volume of a sound to the amount of text selected in an editable text field. For a thorough description of ActionScript's built-in functions, consult the ActionScript Language Reference. Skim it periodically to familiarize yourself with the type of functions that are available, although there is no need to memorize their specific syntax. In addition to the built-in functions that are a native part of the ActionScript language, Macromedia and third parties offer libraries of custom functions that can be incorporated into your movies and used exactly like built-in functions. For more information on extending Flash, see the resources in Appendix A.
Some built-in functions are universally available, while others can be invoked only through an object. If the function is a global function, it can be used anywhere; if the function is a method of an object, however, it must be used in conjunction with the appropriate object. Because we haven't covered objects yet and most of ActionScript's built-in functions are object methods, we'll delay our consideration of the built-in methods until Chapter 12.