Search Tutorials
SummaryThat's how custom functions work. It's just reusable bits of code that you can use anywhere in your script as long as you give it the bits of information it needs to do its job! You make the code run by using a codeword which is the name of the function. In our example: percent(). Defining the function follows the basic steps:
1) work out the tasks that the function will need to do
2) work out what parameters the function will need in order to do its job
3) work out what the function will be returning (if anything)
The format for writing the definition will be
function functionName (parameter,parameter…) {
Tasks here
More tasks
return something (if necessary)
}
Usually we’ll put the function right at the beginning of the code for our movie, because that way, whenever we call the function, we know that Flash has already read the instructions inside that function definition and will know what to do
When we call or invoke a function we do functionName (parameter,parameter)And if the function will return something, then we give the function something to put that value in (usually a variable) variable = functionName (parameter,parameter)There you are. Now all that’s left to do is for you to go off and start writing your own custom functions. Remember, if you have written the same bit of code more than a couple of times in different places, then you might consider writing a function to do the job (it saves on the typing!) A
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||
|