EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Understanding Inheritance and Interfaces

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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.

Table of Contents

Related product manuals