About interfaces
317
4.
Create a new ActionScript file and save it as
MyClass.as
in the same directory as the
IMyInterface.as.
5.
In the MyClass class file, type the following ActionScript code into the Script window:
class MyClass {
}
In order to instruct the custom class (MyClass) to use your interface (IMyInterface), you
need to use the
implements
keyword, which specifies that a class must define all the
methods declared in the interface (or interfaces) that you implement.
6.
Modify the ActionScript code in MyClass.as (add the boldface code) so it matches the
following snippet:
class MyClass
implements IMyInterface
{
}
You place the
implements
keyword after the class name.
7.
Click the Check Syntax button.
Flash displays an error in the Output panel stating that MyClass must implement method
X
from interface IMyInterface. You see this error message because any class that extends an
interface must define each method that’s listed in the interface document.
8.
Modify the MyClass document again (add the boldface code), and write ActionScript code
for the
method1()
and
method2()
methods, as shown in the following snippet:
class MyClass implements IMyInterface {
public function method1():Void {
// ...
};
public function method2(param:String):Boolean {
// ...
return true;
}
}
9.
Save the MyClass.as document and click Check Syntax.
The Output panel no longer displays any error messages or warnings because you have
now defined the two methods.
The class file that you create is not limited to the public methods that you define in the
interface file. The interface file only outlines the minimum methods that you must
implement, as well as those methods’ properties and return types. Classes that implement a
particular interface almost always include additional methods, variables, and getter and
setter methods.
Содержание 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...