First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Andy Armistead (with a little help from FlashGuru)


That'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

» Level Basic

Added: 2001-05-16
Rating: 8 Votes: 185
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.