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
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
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()
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.
keyword, which specifies that a class must define all the
keyword after the class name.
and
methods, as shown in the following snippet:
method2()
About interfaces
317
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?