Introduction to ActionScript Tutorial > Save and retrieve information

 

Save and retrieve information

To create a complex interactive Flash movie, you need a way for Flash to keep track of information and user activity: buttons that have been pressed, a user's name, a score, or what sections a user has visited. ActionScript uses variables to store pieces of information that you can retrieve and use again. You can declare a variable in a script on any Timeline and use it in any other Timeline in the same movie. You must write a target path to a variable in order to use the variable in a script, just as you must write a target path to use a movie clip in a script.

In the puzzle.fla file, ActionScript uses the dialog variable to keep track of whether or not a dialog box is visible. When a dialog box appears, the dialog variable is set to true; when a user clicks a button on a dialog box, the dialog variable is set to false. This variable doesn't affect the visibility of the dialog boxes themselves, it is simply a container that holds information that you can use in scripts throughout the movie. In the puzzle.fla file, if dialog is set to true, a user cannot move a puzzle piece.