Defining Event Handler Methods In Actionscript 1.0 - MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To assign a method to a custom object:
1.
Define the constructor function
function Circle(radius) {
this.radius = radius;
}
2.
Define the
getArea()
area of the circle. In the following example, you can use a function literal to define the
method and assign the
getArea()
Circle.prototype.getArea = function () {
return Math.PI * this.radius * this.radius;
};
3.
The following example creates an instance of the Circle object:
var myCircle = new Circle(4);
4.
Call the
getArea()
var myCircleArea = myCircle.getArea();
trace(myCircleArea); // traces 50.265...
ActionScript searches the
doesn't have a
getArea()
. ActionScript finds it, calls it, and traces
getArea()
Defining event handler methods in
ActionScript 1.0
Many Flash users can greatly benefit from using ActionScript 2.0, especially with
complex applications. For information on using ActionScript 2.0, see
"Classes," on page
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
onClipEvent()
to provide unique instructions that run only when that instance's event occurs. The
and
onClipEvent()
cause their scripts to run. 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.
796
Object-Oriented Programming with ActionScript 1.0
Circle()
method of the Circle object. The
getArea
method of the new
object for the
myCircle
method, its prototype object
225.
or
on()
methods don't override the event handler method; both events
on()
:
getArea()
property to the circle's prototype object:
object using the following code:
myCircle
getArea()
Circle.prototype
myCircleArea
event handler methods to an individual instance
method calculates the
method. Because the object
is searched for
.
Chapter 7,

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents