To assign a method to a custom object:
Define the constructor function
1.
function Circle(radius) {
this.radius = radius;
}
Define the
2.
getArea()
of the circle. In the following example, you can use a function literal to define the
method and assign the
Circle.prototype.getArea = function () {
return Math.PI * this.radius * this.radius;
};
The following example creates an instance of the Circle object:
3.
var myCircle = new Circle(4);
Call the
4.
getArea()
var myCircleArea = myCircle.getArea();
trace(myCircleArea); //traces 50.265...
ActionScript searches the
doesn't have an
. ActionScript finds it, calls it, and traces
getArea()
Defining event handler methods in ActionScript 1
You can create an ActionScript class for movie clips and define the event handler methods in the
prototype object of that new class. Defining the methods in the prototype object makes all the
instances of this symbol respond the same way to these events.
You can also add an
provide unique instructions that run only when that instance's event occurs. The
and
actions don't override the event handler method; both events cause their scripts to run.
on()
However, if you define the event handler methods in the prototype object and also define
an event handler method for a specific instance, the instance definition overrides the
prototype definition.
To define an event handler method in an object's prototype object:
Create a movie clip symbol and set the linkage ID to
1.
Library panel and selecting Linkage from the Library options menu.
In the Actions panel (Window > Development Panels > Actions), use the
2.
define a new class, as shown in the following example:
// define a class
function myClipClass() {}
326
Appendix E: Object-Oriented Programming with ActionScript 1
Circle()
method of the Circle object. The
property to the circle's prototype object:
getArea
method of the new
object for the
myCircle
method, its prototype object
getArea()
or
onClipEvent()
on()
:
getArea()
object using the following code:
myCircle
getArea()
Circle.prototype
myCircleArea
event handler action to an individual instance to
by selecting the symbol in the
theID
method calculates the area
getArea()
method. Because the object
is searched for
.
onClipEvent()
function
action to
Need help?
Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?
Questions and answers