![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
As with any scripting language, ActionScript uses its own terminology. The following list provides an introduction to important ActionScript terms.
Actions are statements that instruct a SWF file to do something while it is playing. For example, gotoAndStop()
sends the playhead to a specific frame or label. In this manual, the terms action and statement are interchangeable.
Boolean is a true
or false
value.
Classes are data types that you can create to define a new type of object. To define a class, you use the class
keyword in an external script file (not in a script you are writing in the Actions panel).
Constants are elements that don't change. For example, the constant Key.TAB
always has the same meaning: it indicates the Tab key on a keyboard. Constants are useful for comparing values.
Constructors are functions that you use to define the properties and methods of a class. By definition, constructors are functions within a class definition that have the same name as the class. For example, the following code defines a Circle class and implements a constructor function:
// file Circle.as class Circle { private var radius:Number private var circumference:Number // constructor function Circle(radius:Number) { circumference = 2 * Math.PI * radius; } }
The term constructor is also used when you create (instantiate) an object based on a particular class. The following statements are constructors for the built-in Array class and the custom Circle class:
my_array:Array = new Array(); my_circle:Circle = new Circle();
Data types describe the kind of information a variable or ActionScript element can hold. The ActionScript data types are String, Number, Boolean, Object, MovieClip, Function, null, and undefined. For more information, see About data types.
Events are actions that occur while a SWF file 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 on the keyboard.
Event handlers are special actions that manage events such as mouseDown
or load
. There are two kinds of ActionScript event handlers: event handler methods and event listeners. (There are also two event handlers, on()
and onClipEvent()
, that you can assign directly to buttons and movie clips.) In the Actions toolbox, each ActionScript object that has event handler methods or event listeners has a subcategory called Events or Listeners. Some commands can be used both as event handlers and as event listeners and are included in both subcategories.
Expressions are any legal combination of ActionScript symbols that represent a value. An expression consists of operators and operands. For example, in the expression x + 2
, x
and 2
are operands and +
is an operator.
Functions are blocks of reusable code that can be passed parameters and can return a value. For more information, see Creating functions.
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. For example, all movie clips are instances of the MovieClip class, so you can use any of the methods or properties of the MovieClip class with any movie clip instance.
Instance names are unique names that let you target movie clip and button instances in scripts. You use the Property inspector to assign instance names to instances on the Stage. For example, a master symbol in the library could be called counter
and the two instances of that symbol in the SWF file could have the instance names scorePlayer1_mc
and scorePlayer2_mc
. The following code sets a variable called score
inside each movie clip instance by using instance names:
_root.scorePlayer1_mc.score += 1; _root.scorePlayer2_mc.score -= 1;
You can use special suffixes when naming instances so that code hints (see Using code hints) appear as you type your code. For more information, see Using suffixes to trigger code hints.
Keywords are reserved words that have special meaning. For example, var
is a keyword used to declare local variables. You cannot use a keyword as an identifier. For example, var
is not a legal variable name. For a list of keywords, see Keywords.
Methods are functions associated with a class. For example, getBytesLoaded()
is a built-in method associated with the MovieClip class. You can also create functions that act as methods, either for objects based on built-in classes or for objects based on classes that you create. For example, in the following code, clear()
becomes a method of a controller
object that you have previously defined:
function reset(){ this.x_pos = 0; this.x_pos = 0; } controller.clear = reset; controller.clear();
Objects are collections of properties and methods; each object has its own name and is an instance of a particular class. Built-in objects are predefined in the ActionScript language. For example, the built-in 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. The values that operators manipulate are called operands.
Parameters (also called arguments) are placeholders that let you pass values to functions. For example, the following welcome()
function uses two values it receives in the parameters firstName
and hobby
:
function welcome(firstName, hobby) { welcomeText = "Hello, " + firstName + "I see you enjoy " + hobby; }
Packages are directories that contain one or more class files, and reside in a designated classpath directory (see Understanding the classpath).
Properties are attributes that define an object. For example, _visible
is a property of all movie clips that defines whether a movie clip is visible or hidden.
Target paths are hierarchical addresses of movie clip instance names, variables, and objects in a SWF file. You name a movie clip instance in the movie clip Property inspector. (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
For more information on target paths, see Using absolute and relative target paths.
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:
var x = 5; var name = "Lolo"; var c_color = new Color(mcinstanceName);
For more information on variables, see About variables.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |