Interface files cannot contain any variable declarations or assignments. Functions that you
declare in an interface cannot contain curly braces. For example, the following interface does
not compile:
interface IBadInterface {
// Compiler error. Variable declarations not allowed in interfaces.
public var illegalVar:String;
// Compiler error. Function bodies not allowed in interfaces.
public function illegalMethod():Void {
}
// Compiler error. Private methods are not allowed in interfaces.
private function illegalPrivateMethod():Void;
// Compiler error. Getters/setters are not allowed in interfaces.
public function get illegalGetter():String;
}
For a tutorial demonstrating how to create a complex interface, see
interfaces" on page
321.
The rules for naming interfaces and storing them in packages are the same as those for classes;
see
"About naming class files" on page
Creating interfaces as data types
Like a class, an interface defines a new data type. You can consider any class that implements
an interface to be of the type that is defined by the interface. This is useful for determining
whether a given object implements a given interface. For example, consider the interface
, which you create in the following example.
IMovable
To create an interface as a data type:
1.
Create a new ActionScript document and save it to your hard disk as IMovable.as.
2.
In IMovable.as, type the following ActionScript code into the Script window:
interface IMovable {
public function moveUp():Void;
public function moveDown():Void;
}
3.
Save your changes to the ActionScript file.
4.
Create a new ActionScript document and save it as Box.as in the same directory as
IMovable.as.
In this document, you create a Box class that implements the IMovable interface that you
created in an earlier step.
318
Interfaces
265.
"Example: Using
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?