MACROMEDIA FLASH MX 2004-USING ACTIONSCRIPT IN FLASH Use Manual page 328

Using actionscript in flash
Hide thumbs Also See for FLASH MX 2004-USING ACTIONSCRIPT IN FLASH:
Table of Contents

Advertisement

myClipClass.prototype.myfunction = function(){
trace("myfunction called");
}
Object.registerClass("myclipID",myClipClass);
this.attachMovie("myclipID","clipName",3);
Creating inheritance in ActionScript 1
Inheritance is a means of organizing, extending, and reusing functionality. Subclasses inherit
properties and methods from superclasses and add their own specialized properties and methods.
For example, reflecting the real world, Bike would be a superclass and MountainBike and Tricycle
would be subclasses of the superclass. Both subclasses contain, or inherit, the methods and
properties of the superclass (for example,
methods that extend the superclass (for example, the MountainBike subclass would have a
property). You can use the elements
ActionScript.
All constructor functions have a
function is defined. The
created with that function. You can use the
to a class. (For more information, see
on page
325.)
All instances of a class have a
inherit. When you use a constructor function to create an object, the
refer to the
prototype
Inheritance proceeds according to a definite hierarchy. When you call an object's property or
method, ActionScript looks at the object to see if such an element exists. If it doesn't exist,
ActionScript looks at the object's
(
myObject.__proto__
ActionScript looks at
The following example defines the constructor function
function Bike(length, color) {
this.length = length;
this.color = color;
this.pos = 0;
}
The following code adds the
Bike.prototype.roll = function() {return this.pos += 20;};
Then, you can trace the position of the bike with the following code:
var myBike = new Bike(55, "blue");
trace(myBike.roll());
trace(myBike.roll());
328
Appendix E: Object-Oriented Programming with ActionScript 1
wheels
prototype
prototype
property indicates the default property values for objects
prototype
prototype
"Assigning methods to a custom object in ActionScript 1"
property that tells you the object from which they
__proto__
property of its constructor function.
__proto__
). If the property is not a property of the object's
myObject.__proto__.__proto__
method to the Bike class:
roll()
// traces 20.
// traces 40.
). Each subclass also has its own properties and
and
to create inheritance in
__proto__
property that is created automatically when the
property to assign properties and methods
property for the information
, and so on.
:
Bike()
property is set to
__proto__
object,
__proto__
gears

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents