MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 316

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

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 application's 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
then left and right curly braces (
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
"Best Practices and Coding Conventions for ActionScript 2.0," on page
creating an application that uses an interface, see
For example, the following code declares an interface named
methods,
method1()
specifies a return type of Void (meaning that it does not return a value). The second method,
, has a single parameter of type String, and specifies a return type of Boolean.
method2()
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.
316
Interfaces
interface
), which define the body of the interface, as shown in the
{}
and
. The first method,
method2()
keyword, followed by the interface name, and
"Example: Using interfaces" on page
IMyInterface
method1()
Chapter 19,
731. For a tutorial on
321.
that contains two
, has no parameters and

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents