8.
In ClassA.as, type the following ActionScript code into the Script window:
class ClassA implements Ib {
// f1() and f2() are defined in interface Ia.
public function f1():Void {
}
public function f2():Void {
}
// f8() and f9() are defined in interface Ib, which extends Ia.
public function f8():Void {
}
public function f9():Void {
}
}
9.
Save your class file and click the Check Syntax button above the Script window.
Flash doesn't generate any error messages as long as all four methods are defined and
match the definitions from their respective interface files.
Classes are only able to extend one class in ActionScript 2.0, although you can use
classes to implement as many interfaces as you want.
If you want your ClassA class to implement multiple interfaces in the previous example, you
would simply separate the interfaces with commas. Or, if you had a class that extended a
superclass and implemented multiple interfaces, you would use code similar to the following:
class ClassA extends ClassB implements Ib, Ic, Id {...}.
Example: Using interfaces
In this example you create a simple interface that you can reuse between many
different classes.
To build an interface:
1.
Create a new ActionScript file and save it as IDocumentation.as.
2.
In IDocumentation.as, type the following ActionScript code into the Script window:
interface IDocumentation {
public function downloadUpdates():Void;
public function checkForUpdates():Boolean;
public function searchHelp(keyword:String):Array;
}
3.
Save the changes that you made to the ActionScript interface file.
4.
Create a new ActionScript file in the same directory as the IDocumentation.as file, and save
this new file as FlashPaper.as.
Example: Using interfaces
321
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?
Questions and answers