Using Polymorphism In An Application - MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

11.
Open the SubWidget class and add a new method named
class so that it matches the following code (add the code that's in boldface):
class SubWidget extends Widget {
public function SubWidget() {
trace("Creating subwidget # " + Widget.widgetCount);
doSomething();
}
public function doSomething():Void {
trace("SubWidget::doSomething()");
}
}
12.
Save your changes to the class file, and then open subwidgetTest.fla again.
13.
Select Control > Test Movie to test the file. You see the following output in the
Output panel:
Creating subwidget # 1
SubWidget::doSomething()
Creating subwidget # 2
SubWidget::doSomething()
The previous output shows that the
constructor is calling the
the superclass.
Open the SubWidget class again, and modify the SubWidget class's constructor to call the
superclass's
doSomething()
public function SubWidget() {
trace("Creating subwidget # " + Widget.widgetCount);
super.doSomething();
}
As demonstrated, you can add the
method instead of the
information on
super
14.
Save the SubWidget class file with the modified constructor and select Control > Test
Movie to republish the Flash document.
The Output panel displays the contents of the Widget class's

Using polymorphism in an application

Object-oriented programming lets you express differences between individual classes using a
technique called polymorphism, by which classes can override methods of their superclasses
and define specialized implementations of those methods.
308
Inheritance
doSomething()
method in the current class instead of
doSomething()
method (add the code that's in boldface):
keyword to call the superclass's
super
method in the current class. For additional
doSomething()
, see the
entry in the ActionScript 2.0 Language Reference.
super
doSomething()
method in the SubWidget class's
doSomething()
doSomething()
. Modify your
method.

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