As we saw on the previous page, assignment statements can be used to assign values to variables. They can be combined with declaration statements to both declare a variable and assign it a value, or the declaration and assignment may be done separately. A variable is a named spot set aside in memory, of a particular type (class or primitive datatype), where values may be stored and retrieved as a Flash movie is executing. A variable can also be viewed as a property of a particular timeline (the timeline on which it is declared). Each timeline has its own set of variables, which are user-defined properties added to the built-in properties that every timeline (ie, instance of MovieClip class) already has. Starting with Flash MX 2004 (Flash 7), variables can and should be defined as being of a particular type when they are declared.
The general form for such a declaration is:

Classname is capitalized because class names usually are. A couple examples:
var addresses:Array; // addresses is a variable which is an instance of the Array class var n:Number; // n is a numeric variable (and so can only have numeric values)
These statements create variables of the specified type (class or datatype) in the timeline where this code is. They will be given values later in the program. Here, a marked spot in memory is set aside for each.
If a value is to be assigned to the variable when it is declared, then the general form is:

For example:
var id:String = "sac002";
This creates a variable id, of type String, on the current timeline, and assigns the string of characters, 'sac002', to it. That is the variable's initial value; it may changed to some other string value later in the program. If, later in the movie, you assign an obvious numeric value (without quotes around it to make it a string), you'll see an error in the Output panel.
var finished:Boolean = false;
Variable finished is created and set initially to false. Presumably it will be set to true by something later in the movie. Never put quotes around true or false when assigning values to Boolean variables or properties.
var zipcodes:Array = new Array('20852', '40938', '50392');
Variable zipcodes, an instance of the Array class, is created and assigned an initial value by passing parameters to it. The parameters in this case (whenever you create an Array instance) are the elements of the array. An array is a good way to store repetitive data -- more about arrays can be found here.
If the variable has already been declared (and associated with a timeline, as it is automatically when it is declared), then the general form of the assignment statement is:

For example:
id = "mpx005";
This sets the value of variable id in the current timeline to "mpx005". It assumes that the variable id has already been declared as a variable of type String.
bee1_mc.stopped = true;
This statement assumes that a variable (property) stopped has already been declared for bee1_mc (or, if not, one is created when the statement executes). The value of true is assigned to bee1_mc's variable (property) named stopped. bee1_mc must be a movieclip in the same timeline as this code for this statement to work.
As we saw in the last statement above, an assignment statement can be used to assign a value to a particular property of an instance.
Notice that properties themselves are always instances of a particular class.
Movieclip instances, for example, have built-in properties such as _alpha, _visible, and _xscale which can be read and set with actionscript. This is the general form for assigning a value to a property:

eg,
racecar_mc._alpha = 70;
This statement causes the movieclip named racecar_mc, located in the same timeline and same frame where the statement is, to be set to 70% opacity. If the statement exists in a frame of the main timeline where the racecar_mc is not also present, it will have no affect. _alpha is a property which has a value of type Number assigned to it.
_parent.plane_mc._visible = false;
This statement causes the movieclip plane_mc, in the timeline above the one in which this code is written, to be invisible. Notice that the value assigned to the _visible property is false, with no quotes around it. _visible is a property which can only have a value of type Boolean (specified as either true or false) assigned to it (though you may see examples of a 1 or 0 being assigned to a Boolean property, which happens to work in Flash, because Flash automatically converts the number 0 to Boolean false, or 1 to true, before assigning it.)
A function is also a kind of datatype; that is, when you declare or create a function in Flash, you're creating a variable of type function. A spot in memory is set aside which points to the code (the set of statements) included in the function. If the function is named, that name is associated with (points to) the function's spot in memory (the place where all of its code is stored). If it's not named, Flash still keeps a reference to it, so it can be assigned to something else, like a movieclip event handler. Here are examples of a function declaration and two different kinds of assignments, in both of which a function is assigned to a movieclip property:
// declaring (and defining) a function named makePictureWider
function makePictureWider() {
picture_mc._xscale *= 1.5;
}
// assigning that function to a movieclip property
control_mc.onRelease = makePictureWider;
// assigning an unnamed function to a movieclip property
// because this is an assignment statement, it has a semicolon at the end
// its effect is the same as the two examples above combined
control_mc.onRelease = function() {
picture_mc._xscale *= 1.5;
};
Discussed on this page:
declare variable, assign value to variable, every variable is a property of a timeline