User Guide

26 Chapter 2: ActionScript Basics
Instance names are unique names that let you target instances you create, or movie clip and
button instances on the Stage. For example, in the following code, “names” and “studentName
are instance names for two objects, an array and a string:
var names:Array = new Array();
var studentName:String = new String();
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:
this.scorePlayer1_mc.score = 0;
this.scorePlayer2_mc.score = 0;
You can use strict data typing when creating instances so that code hints (see “Using code hints
on page 147) appear as you type your code. For more information, see “Strictly typing objects to
trigger code hints” on page 145.
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 and reserved words” on page 32.
Methods are functions associated with a class. For example, sortOn() is a built-in method
associated with the Array 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.y_pos = 0;
}
controller.clear = reset;
controller.clear();
The following examples show how you create methods of a class:
//ActionScript 1 example
A = new Object();
A.prototype.myMethod = function() {
trace("myMethod");
}
//ActionScript 2 example
class B {
function myMethod() {
trace("myMethod");
}
}
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 class provides information from the system clock.