Functions
Top  Previous  Next


Scripting Objects can also contain functions. Functions are a way of creating re-useable sections of script. This can increase the modularity and readability of your Script.

Functions are an ideal way of expanding the methods that can be applied to a particular Object. Functions that are defined within an Object are local to that Object.

If you wish to create functions that are available to all Objects, either create them in the main Movie (they will then be available as _root.function()), or create a Sprite specifically to hold these functions (they will then be available as _root.spritename.function()).

For example, a function MoveToZero() can be defined to move an Object to position 0.

Function
 MoveToZero() { 
   _x = 0; 
   _y = 0; 
}


The script command
ball.MoveToZero(); will cause the ball object to move to 0,0

In this case MoveToZero() is effectively a local method of the ball Object.