Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 140

Programming actionscript 3.0
Table of Contents

Advertisement

To create a class in ActionScript 1.0, you define a constructor function for that class. In
ActionScript, functions are actual objects, not just abstract definitions. The constructor
function that you create serves as the prototypical object for instances of that class. The
following code creates a class named Shape and defines one property named
set to
by default:
true
// base class
function Shape() {}
// Create a property named visible.
Shape.prototype.visible = true;
This constructor function defines a Shape class that you can instantiate with the
as follows:
myShape = new Shape();
Just as the Shape constructor function object serves as the prototype for instances of the Shape
class, it can also serve as the prototype for subclasses of Shape—that is, other classes that
extend the Shape class.
The creation of a class that is a subclass of the Shape class is a two-step process. First, create
the class by defining a constructor function for the class, as follows:
// child class
function Circle(id, radius)
{
this.id = id;
this.radius = radius;
}
Second, use the
operator to declare that the Shape class is the prototype for the Circle
new
class. By default, any class you create uses the Object class as its prototype, which means that
currently contains a generic object (an instance of the Object class). To
Circle.prototype
specify that Circle's prototype is Shape instead of Object, use the following code to change the
value of
Circle.prototype
// Make Circle a subclass of Shape.
Circle.prototype = new Shape();
140
Object-Oriented Programming in ActionScript
so that it contains a Shape object instead of a generic object:
that is
visible
operator,
new

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents