Example: Using interfaces
321
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.
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.
NO
TE
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.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...