EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Creating Interfaces as Data Types

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

Table of Contents

Related product manuals