MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 307

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

3.
Save your changes to the ActionScript document.
The Widget class now defines a constructor and a public method called
4.
Create a new ActionScript file named SubWidget.as and save it in the same directory
as Widget.as.
If you created the SubWidget class in
on page
304, you can use this file instead.
5.
In SubWidget.as, type the following ActionScript code into the Script window:
class SubWidget extends Widget {
public function SubWidget() {
trace("Creating subwidget # " + Widget.widgetCount);
doSomething();
}
}
6.
Save your changes to SubWidget.as.
Notice that the SubWidget class's constructor calls the
defined in the superclass.
7.
Create a new Flash document and save it as subWidgetTest.fla in the same directory as the
ActionScript documents.
8.
In subWidgetTest.fla, type the following ActionScript into Frame 1 of the main Timeline:
var sw1:SubWidget = new SubWidget();
var sw2:SubWidget = new SubWidget();
9.
Save your changes to the Flash document.
10.
Select Control > Test Movie to test the Flash document. You see the following output in
the Output panel:
Creating subwidget # 1
Widget::doSomething()
Creating subwidget # 2
Widget::doSomething()
This output shows that the SubWidget class's constructor calls the constructor of its
superclass (Widget), which increments the static
constructor traces the superclass's static property and calls the
which inherits from the superclass.
"Example: Extending the Widget class"
doSomething()
property. The SubWidget's
widgetCount
doSomething()
About writing subclasses in Flash
.
doSomething()
method that you
method,
307

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?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents