EasyManua.ls Logo

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

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...
316 Interfaces
Defining and implementing interfaces
The process for creating an interface is the same as for creating a class. Like classes, you can
define interfaces only in external ActionScript files. At a minimum, the workflow for creating
an interface involves the following steps:
Defining a interface in an external ActionScript file
Saving the interface file to a designated classpath directory (a location where Flash looks
for classes) or in the same directory as the applications FLA file
Creating an instance of the class in another script, either in a Flash (FLA) document or an
external script file, or subinterfaces based on the original interface
Creating a class that implements the interface in an external script file
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, as shown in the
following example:
interface IEmployeeRecords {
// interface method declarations
}
An interface can contain only method (function) declarations, including parameters,
parameter types, and function return types.
For more information on conventions for structuring classes and interfaces, see Chapter 19,
“Best Practices and Coding Conventions for ActionScript 2.0,” on page 731. For a tutorial on
creating an application that uses an interface, see “Example: Using interfaces” on page 321.
For example, the following code declares an interface named
IMyInterface that contains two
methods,
method1() and method2(). The first method, method1(), has no parameters and
specifies a return type of Void (meaning that it does not return a value). The second method,
method2(), has a single parameter of type String, and specifies a return type of Boolean.
To create a simple interface:
1. Create a new ActionScript file and save it as IMyInterface.as.
2. Type the following ActionScript code into the Script window:
interface IMyInterface {
public function method1():Void;
public function method2(param:String):Boolean;
}
3.
Save your changes to the ActionScript file.
In order to use the interface within an application, you first need to create a class that
implements your new interface.

Table of Contents

Related product manuals