Skip Navigation.

Flash: Functions

ActionScript includes many sub-programs that do specific things for your program. For instance, on the properties page of this help section, we've used the setProperty function, which allows a user to set a property on an object to a certain value.

This page will explain how to use ActionScript functions, where to find ActionScript functions, and finally, how to write your own ActionScript function.

How to use ActionScript Functions

Function window with arguments
below ActionScript functions can be added to your code in two ways:

  1. In Normal mode you can double-click on the function in the actions section of the Actions Window to place the function in the code section.
  2. In Expert mode you can type the function into the code section of the Actions Window by hand.

Once you have a function in the code section of your Actions Window, you need to set the arguments for that function. Arguments are pieces of data the function needs to perform. For instance, if you're using the setProperty function, you need to supply three arguments: object name, property name, value to set.

To supply arguments for your function, you simply click on the function to select it, and then fill in the data for the arguments in the details section (as shown at right). If you're using Expert mode, you can just type the arguments in the code section itself.


Where to find ActionScript Functions

Flash's Actions Window allows users working in Normal mode to use the ActionScript functions easily in their code. To add a function to your code, find it in the actions section and double-click it or drag it over to the code section.

To edit the arguments for the code, select the code by clicking on it, and the details window below will show you the arguments. The arguments available for each function vary wildly depending on the function. For the one in our example, the details are:


How to create ActionScript Functions

Sometimes, you will want a function that does something simple, but you may want to do it many times in a program. You can then make your own function to perform that action.

To make your own function, first double-click on function in the action section of the Actions Window. The following code will appear:

Code for make-your-own function

The name of the function appears in the area marked "Not yet set" and the arguments for that function appear in between the parentheses. The actions the function takes will be contained between the two curly braces.

Once you've made your new function and named it, you can call it anytime by using its name and arguments.

Back