EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 317

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...
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.

Table of Contents

Related product manuals