EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 807

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
807
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.0 example
A = new Object();
A.prototype.myMethod = function() {
trace("myMethod");
}
//ActionScript 2.0 example
class B {
function myMethod() {
trace("myMethod");
}
}
Named function
is a kind of function that you commonly create in your ActionScript code to
carry out all kinds of actions. For information and an example, see Writing named functions
on page 207.
Object code is ActionScript that you attach to instances. To add object code, you select an
instance on the Stage and then type code into the Actions panel. Attaching code to objects on
the Stage is not recommended. For information on best practices, see “Best Practices and
Coding Conventions for ActionScript 2.0” on page 731.
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.
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.

Table of Contents

Related product manuals