User Guide

Using the call() function to create functions 13
Using the call() function to create
functions
You cant define or call custom functions in Flash Lite as you can in Flash Player 5 and later.
However, you can use the
call() ActionScript function to execute code that resides on an
arbitrary frame in the timeline. This technique lets you encapsulate commonly used code in a
single location, making it easier to maintain.
The
call() function takes a frame number or frame label as a parameter. For example, the
following ActionScript calls the code located on the frame labeled
moveUp:
call("moveUp");
The call() function operates synchronously; any ActionScript that follows a call()
function call wont execute until all of the ActionScript on the specified frame finishes
executing.
To call ActionScript on another frame:
1. In a new Flash document, insert a keyframe on Frame 10.
2. With the new keyframe selected, open the Actions panel (Window > Actions), and type the
following code:
trace("Hello from frame 10");
3.
Select the keyframe on Frame 1, and in the Actions panel, type the following code:
stop();
call(10);
This code stops the playhead on Frame 1, and then calls the code on Frame 10.
4. Test the application in the emulator and open the Output panel (Window > Output).
You should see “Hello from frame 10” displayed in the Output panel.