ActionScript functions

There are many built-in functions available in Flash. These include math functions, string functions, and the other functions normally found in a programming language.

In addition you can define functions of your own. User-defined functions are written in keyframes in the timeline. To keep life simple, it's easiest just to type in all your functions (if possible) in the first keyframe on the top layer of your main timeline.

The basic form of a function is:

function doSomething( ) {



Using functions as event handlers for UI (user interface) components.

Once you have created a function you can have it run automatically in response to an event associated with a component like a check box, push button, etc. Just create the function in a keyframe on your main timeline and type in the name of the function in the Property Inspector parameters for the component as the Change Handler option.

If more than one component is handled by the same function, you should provide a parameter for the function which will automatically be set to the component that triggers the event when the function is called. In the example below all the checkboxes use the same Change Handler function called checkBox. The parameter box represents whichever check box has been clicked. The built-in function getValue will return the data field from a combo or list box or returns true/false for checked/unchecked with radio buttons and check boxes. The function checks the box to see if there is a check in it (box.getValue is true) or not (box.getValue is false).

function checkBox(box){
   if (box.getValue( )) count++;