[Previous] [TOC] [Next]

Write a function for the Try Again button


A function is a script that you can use repeatedly to perform a specific task. You can pass parameters to a function, and it can return a value. In this example, when the user clicks the Try Again button, a function runs that returns the playhead to Frame 1.

You'll write that function now. In this script, you'll type the frame number, because you did not label Frame 1.

1.
In the Timeline, select Frame 5 of the Actions layer.

2.
In the Script pane, type the following comment:

// button function returns user to Frame 1.

Press Enter (Windows) or Return (Macintosh).

3.
Type tryAgain_btn.onRelease = function(){, and then press Enter or Return.

4.
Type gotoAndStop(1);, and then press Enter or Return and type } to complete the script.

[Previous] [TOC] [Next]