318
Interfaces
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
“Example: Using
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 265
.
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
IMovable
, which you create in the following example.
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.
Содержание 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...