So, what is a function, and what do they do? Well, to put it simple. A function can be a command that tells the flash movie to do something. Like to stop at frame 12.
The stop function as shown below is what we call a built in global function. A lot of difficult words, I know.
When a flash movie gets to frame 12 and in that frame there is a function called "stop()", it will read it and understand that this is a built in function, and that it has to do something. This function is pretty easy to understand. Everyone can see that when flash reads the code it will stop the movie at frame 12.
There are many different built in functions that you have to use if you want to make your flash movie interactive. Some of the most important include stop, gotoAndPlay, play, on, nextFrame, prevFrame and so on.
But you can also create your own function! If you're using the same code snippet over and over throughout the movie, you may want to create a function that can execute the code in one word instead of copying the code snippet several times during a movie.
The code shown below is an example of a code that may be used several times during a movie. So instead of copying and pasting the same code over and over again, we can create our own function.
If you take a look at the image below, you can see how you create your own function. You type "function", then the name of your function, an opening and closing parenthesis, an opening curly brace and a closing curly brace at the end. Then you insert the code you created earlier between the two curly braces as shown in the image below.
You have created your own function! But what do you have to do if you want to execute the function? Say you have created a button in the main timeline and everytime you push the button, the function will be executed.
To do that you have to select the button in the main timeline and write a well known "on(release)" function. Within the "on(release)" function type the name of the function you just created, as shown in the image below.
Remember that all functions have to include an opening and closing parenthesis at the end.
If your button is located within a movie clip on the main timeline like this:
Main timeline - myMovieClip - myButton. And you want to execute the function that you wrote in the first frame on the main timeline you have to do like this:
That's the basics of functions! If you want to know more, sign up at our forums and we will help you!




