Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 131

Programming actionscript 3.0
Table of Contents

Advertisement

}
var cir:Circle = new Circle();
trace(cir.area()); // 3.141592653589793
var sq:Square = new Square();
trace(sq.area()); // 1
Because each class defines a data type, the use of inheritance creates a special relationship
between a base class and a class that extends it. A subclass is guaranteed to possess all the
properties of its base class, which means that an instance of a subclass can always be
substituted for an instance of the base class. For example, if a method defines a parameter of
type Shape, it is legal to pass an argument of type Circle because Circle extends Shape, as in
the following:
function draw(shapeToDraw:Shape) {}
var myCircle:Circle = new Circle();
draw(myCircle);
Instance properties and inheritance
An instance property, whether defined with the
inherited by all subclasses as long as the property is not declared with the
the base class. For example, the Event class in the Flash Player API has a number of subclasses
that inherit properties common to all event objects.
For some types of events, the Event class contains all the properties necessary to define the
event. These types of events do not require instance properties beyond those defined in the
Event class. Examples of such events are the
loaded successfully, and the
been established.
The following example is an excerpt from the Event class that shows some of the properties
and methods that are inherited by subclasses. Because the properties are inherited, an instance
of any subclass can access these properties.
public class Event
{
public function get type():String;
public function get bubbles():Boolean;
...
public function stopPropagation():void {}
public function stopImmediatePropagation():void {}
public function preventDefault():void {}
public function isDefaultPrevented():Boolean {}
function
complete
event, which occurs when a network connection has
connect
,
, or
keywords, is
var
const
private
event, which occurs when data has
attribute in
Inheritance
131

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents