On the previous page, we looked at some examples of function call statements. gotoAndPlay is one such function, which we saw is always applied to an instance of a movieclip. To be more precise, we can say that gotoAndPlay is a method of the MovieClip class and thus is available to be called by any instance of that class.
The instance of the MovieClip class which called gotoAndPlay in our example statement was plane_mc. A movieclip instance is just one example of an instance of a class. Flash contains a wide variety of predefined classes, including MovieClip, Array, Date, and XML, to name a few. In addition to the built-in classes, you can also define your own class in an actionscript class file. Regardless of the origin of the class, built-in or user-defined, all have the same structure -- each consists of a defined set of properties, which describe the attributes of the class, and a defined set of methods, which are functions that carry out behaviors specific to that class. When an instance of a class is created (like a movieclip on stage), the properties of that instance are set to some initial value (eg, _visible is set true, _xscale is set to 100, _alpha is set to 100) and may be changed through actionscript during program execution.
Below is a picture of 4 instances of the same movieclip, with some of the properties of each (except one) shown. All movieclips have the same collection of properties, but each instance has its own value for each property. Descriptions of some movieclip properties are listed on the Movieclip Reference page. For a complete listing of all properties and methods of the MovieClip class, open the Flash help (F1) and look in the Help Tab under Actionscript Language Reference, M, MovieClip class. You can find documentation on every built-in Flash class in the same way. They are also available online in the Actionscript Reference part of Macromedia's livedocs online documentation for Flash (click the link for Actionscript Language Reference on the left).
The MovieClip class is a class whose instances are visible on stage. Most classes have instances which are not visible but serve to hold or manipulate data in some useful way. For example, if you wanted to keep of list of mp3 titles to use in your Flash movie, you could create an instance of the Array class:
var songtitles:Array = ["Times Have Changed", "Good To Me", "A Woman Will Do Wrong"];
That statement contains both a declaration of the instance, and assignment of a value to it. The declaration and assignment are sometimes done in separate statements (especially if the value that will be assigned is not known at the time the instance is declared), like this:
var songtitles:Array; songtitles = ["Times Have Changed", "Good To Me", "A Woman Will Do Wrong"];
When an instance of some class that is used for saving or manipulating data is created, it is often referred to as a variable. A variable (instance of a class) can be created by executing the class's constructor, with or without parameters, eg
var songtitles:Array = new Array("Times Have Changed", "Good To Me", "A Woman Will Do Wrong");
or, in some instances, with a shorthand notation that does the same thing, as shown in the songtitles assignment shown above. When an instance of a class has been created, all of the properties of that class (such as length for Arrays) and methods of that class (such as sortOn for Arrays) become available for use by that instance. Examples of Array methods in use may be found on the Arrays and Objects page.
Primitive variables can be created by specifying their datatype (like, but not exactly the same as, a class). Primitive datatypes include Number, String, and Boolean. Here's an example of a variable of type Number being created and used to store the x location of a movieclip on stage:
var xcar:Number; xcar = racecar_mc._x;
The first statement declares a variable xcar of type Number (meaning that only numeric values can be assigned to it). It tells the compiler to set aside a location in memory that will hold information of type Number and name it xcar. The second statement assigns the current value of the _x property of movieclip racecar_mc to that variable -- that is, it saves that value in the memory location that was set aside for xcar.
The next page has more details about variables, properties, and assignment statements.
Discussed on this page:
class, property, method, storing data, datatype, Array, using flash help, online documentation