set variable

Availability

Flash Player 4.

Usage

set(variable, expression)

Parameters

variable An identifier to hold the value of the expression parameter.

expression A value assigned to the variable.

Returns

Nothing.

Description

Statement; assigns a value to a variable. A variable is a container that holds data. The container itself is always the same, but the contents can change. By changing the value of a variable as the SWF file plays, you can record and save information about what the user has done, record values that change as the SWF file plays, or evaluate whether a condition is true or false.

Variables can hold any data type (for example, String, Number, Boolean, Object, or MovieClip). The Timeline of each SWF file and movie clip has its own set of variables, and each variable has its own value independent of variables on other Timelines.

Strict data typing is not supported inside a set statement. If you use this statement to set a variable to a value whose data type is different from the data type associated with the variable in a class file, no compiler error is thrown.

Example

This example sets a variable called orig_x_pos, which stores the original x axis position of the ship movie clip in order to reset the ship to its starting location later in the SWF file.

on(release) {
  set("orig_x_pos", getProperty ("ship", _x ));
}

The previous code gives the same result as the following code:

on(release) {
  orig_x_pos = ship._x;
}

See also

var, call()