![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
The process for creating an interface is the same as for creating a class. As with classes, you can only define interfaces in external ActionScript (AS) files. You declare an interface using the interface
keyword, followed by the interface name, and then left and right curly braces, which define the body of the interface.
interface interfaceName { // interface method declarations }
An interface can contain only method (function) declarations, including parameters, parameter types, and function return types.
For example, the following code declares an interface named MyInterface that contains two methods, method_1()
and method_2()
. The first method takes no parameters and has no return type (specified as Void
). The second method declaration takes a single parameter of type String, and specifies a return type of Boolean.
interface MyInterface { function method_1():Void; function method_2(param:String):Boolean; }
Interfaces cannot contain any variable declarations or assignments. Functions declared in an interface cannot contain curly braces. For example, the following interface won't compile.
interface BadInterface{ // Compiler error. Variable declarations not allowed in interfaces. var illegalVar; // Compiler error. Function bodies not allowed in interfaces. function illegalMethod(){ } }
The rules for naming interfaces and storing them in packages are the same as those for classes; see Creating and using classes and Using packages.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |