home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeActionScript: The Definitive GuideSearch this book

9.10. Internal Functions

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. You hopefully will have noticed that you invoke built-in functions using the function-call operator (the parentheses) and a parameter 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 building ourselves. Naturally, the built-in functions do different things than our custom functions, and there is no sense in writing a custom function to do something that a built-in ActionScript function already offers. But like any custom function, each built-in function has a name, optional parameters, and a return value (although sometimes it's undefined).

Even though Flash has long referred to gotoAndPlay as an "Action," we now see it in its true form, as an internal function. In Chapter 6, "Statements" we 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 looking upon 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 Part III, "Language Reference", we find the info and can easily put together a statement like this:

loadMovie("myMovie.swf", 1);

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 an exhaustive list of ActionScript's built-in functions, consult Part III, "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.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.