Understanding ActionScript > ActionScript terminology
ActionScript terminologyLike any scripting language, ActionScript uses specific terminology according to specific rules of syntax. The following list provides an introduction to important ActionScript terms in alphabetical order. These terms and the syntax that governs them are discussed in more detail in Writing scripts with ActionScript: Overview.
Actions are statements that instruct a movie to do something while it is playing. For example, gotoAndStop
sends the playhead to a specific frame or label. In this book, the terms action and statement are interchangeable.
Arguments, also called parameters, are placeholders that let you pass values to functions. For example, the following function, called welcome
, uses
two values it receives in the arguments firstName
and hobby
:
function welcome(firstName, hobby) { welcomeText = "Hello, " + firstName + "I see you enjoy " + hobby; }
Classes are data types that you can create to define a new type of object. To define a class of object, you create a constructor function.
Constants are elements that don't change. For example, the constant TAB
always has the same meaning. Constants are useful for comparing values.
Constructors are functions that you use to define the properties and methods of a class. For example, the following code creates a new Circle class by creating a constructor function called Circle
:
function Circle(x, y, radius){ this.x = x; this.y = y; this.radius = radius; }
Data types are a set of values and the operations that can be performed on them. String, number, true
and false
(Boolean) values, object, and movie clip are the ActionScript data types. For more details on these language elements, see About data types.
Events are actions that occur while a movie is playing. For example, different events are generated when a movie clip loads, the playhead enters a frame, the user clicks a button or movie clip, or the user types at the keyboard.
Expressions are any parts of a statement that produce a value. For example, 2 + 2
is an expression.
Functions are blocks of reusable code that can be passed arguments (parameters) and can return a value. For example, the getProperty
function is passed the name of a property and the instance name of a movie clip, and it returns the value of the property. The getVersion
function returns the version of the Flash Player currently playing the movie.
Handlers are special actions that "handle" or manage an event such as mouseDown
or load
. For example, on (onMouseEvent)
and onClipEvent
are ActionScript handlers.
Identifiers are names used to indicate a variable, property, object, function, or method. The first character must be a letter, underscore(_), or dollar sign($). Each subsequent character must be a letter, number, underscore(_), or dollar sign($). For example, firstName
is the name of a variable.
Instances are objects that belong to a certain class. Each instance of a class contains all the properties and methods of that class. All movie clips are instances with properties (for example, _alpha
, and _visible
) and methods (for example, gotoAndPlay
, and getURL
) of the MovieClip class.
Instance names
are unique names that allow you to target movie clip instances in scripts. For example, a master symbol in the Library could be called counter
and the two instances of that symbol in the movie could have the instance names scorePlayer1
and scorePlayer2
. The following code sets a variable called score
inside each movie clip instance by using instance names:
_root.scorePlayer1.score += 1 _root.scorePlayer2.score -= 1
Keywords are reserved words that have special meaning. For example, var
is a keyword used to declare local variables.
Methods are functions assigned to an object. After a function is assigned, it can be called as a method of that object. For example, in the following code, clear
becomes a method of the controller
object:
function Reset(){ x_pos = 0; x_pos = 0; } controller.clear = Reset; controller.clear();
Objects are collections of properties; each object has its own name and value. Objects allow you to access a certain type of information. For example, the predefined Date object provides information from the system clock.
Operators are terms that calculate a new value from one or more values. For example, the addition (+
) operator adds two or more values together to produce a new value.
Target paths are hierarchical addresses of movie clip instance names, variables, and objects in a movie. You can name a movie clip instance in the Instance panel. The main Timeline always has the name _root
. You can use a target path to direct an action at a movie clip or to get or set the value of a variable. For example, the following statement is the target path to the variable volume
inside the movie clip stereoControl:
_root.stereoControl.volume
Properties are attributes that define an object. For example, _visible
is a property of all movie clips that defines whether the movie clip is visible or hidden.
Variables are identifiers that hold values of any data type. Variables can be created, changed, and updated. The values they store can be retrieved for use in scripts. In the following example, the identifiers on the left side of the equal signs are variables:
x = 5; name = "Lolo"; customer.address = "66 7th Street"; c = new Color(mcinstanceName);