320
Interfaces
This ActionScript code checks whether the
newBox
instance implements the IMovable
interface before you call the
moveUp()
method on the object.
11.
Save the Flash document, and then select Control > Test Movie to test the SWF file.
Because the Box instance implements the IMovable interface, the
Box.moveUp()
method
is called, and the text “moving up” appears in the Output panel.
For more information about casting, see
Chapter 4, “About casting objects,” on page 111
.
Understanding inheritance and interfaces
You can use the
extends
keyword to create subclasses of an interface. This can be very useful
in larger projects for which you might want to extend (or
subclass
) an existing interface and
add additional methods. These methods must be defined by any classes implementing
that interface.
One consideration you need to make when extending interfaces is that you receive error
messages in Flash if multiple interface files declare functions with the same names but have
different parameters or return types.
The following example demonstrates how you can subclass an interface file using the
extends
keyword.
To extend an interface:
1.
Create a new ActionScript file, and then save it as
Ia.as
.
2.
In Ia.as, type the following ActionScript code into the Script window:
interface Ia {
public function f1():Void;
public function f2():Void;
}
3.
Save your changes to the ActionScript file.
4.
Create a new ActionScript file and save it as
Ib.as
in the same folder as the Ia.as file you
created in step 1.
5.
In Ib.as, type the following ActionScript code into the Script window:
interface Ib extends Ia {
public function f8():Void;
public function f9():Void;
}
6.
Save your changes to the ActionScript file.
7.
Create a new ActionScript file and save it as
ClassA.as
in the same directory as the two
previous files.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...