var
Top  Previous  Next


SWiSH Player Support
SWF5 or later - Supported Internally

Syntax

var variableName [ : typeName1 ] [= value1] [...,variableNameN [ : typeNameN ] [= valueN]]

Arguments
variableName An identifier.

typeName A type keyword, one of String, Number of Boolean

value The value assigned to the variable.

Returns
Nothing.

Description
Action: used to declare local or Timeline variables.

If you declare variables inside a function, the variables are local. They are defined for the function and expire at the end of the function call. Otherwise the variables are interpreted as Timeline variables. However, you don't have to use var to declare Timeline variables.

The var statement supports optional types. These types may be used by the SWISHscript compiler to test whether the values assigned to variables are of the expected type, and that the variable is not used where a different type of value is required. Types can include Number, Boolean or String. The type checking may not occur in some cases.

Sample:

function f ( x ) {
    var y = x +1;
    return y*y;
}


// the variable y is local to the function