Understanding the ActionScript Language > Creating functions > Calling a user-defined function |  |

Calling a user-defined function

You can use a target path to call a function in any Timeline from any Timeline, including from the Timeline of a loaded movie. If a function was declared using the `_global` identifier, you do not need to use a target path to call it.

To invoke a function using the Actions panel in normal mode, you use the `call function` action. Pass the required parameters inside parentheses. You can call a function in any Timeline from any Timeline, including a loaded movie. For example, the following statement invokes the function `sqr` in the movie clip `MathLib` on the main Timeline, passes it the parameter 3, and stores the result in the variable `temp`:

    var temp = _root.MathLib.sqr(3);

To call a user-defined function in normal mode:

1 | Choose Window > Actions to open the Actions panel.
2 | In the Actions toolbox (at the left of the panel), click the Actions folder, then click the User-Defined Functions folder.
3 | Double-click the `call` `function` action.
4 | In the Object box, enter the target path of the movie clip in which the function was defined. You can use the Insert Target Path button to enter the target path.
5 | In the Method box, enter the name of the function.
6 | In the Parameters box, enter the names of parameters, if any, separated by commas.

For information on target paths, see Writing a target path. For more information on each function, see individual entries in the online ActionScript Dictionaryin the Help menu.

To call a function in expert mode:

Enter the target path to the name of the function. Pass any required parameters inside parentheses.

The following example uses an absolute path to call the `initialize` function that was defined on the main Timeline and requires no parameters:

    _root.initialize();

The following example uses a relative path to call the `list` function that was defined in the `functionsClip` movie clip:

    _parent.functionsClip.list(6);

For more information about using the Actions panel, see Working in normal mode and Working in expert mode.