O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interface Syntax and Use

Recall that an interface defines a new datatype without implementing any of the methods of that datatype. Thus, to create an interface, we use the following syntax:

interface SomeName {
  function method1 (param1:datatype,...paramn:datatype):returnType;
  function method2 (param1:datatype,...paramn:datatype):returnType;
  ...
  function methodn (param1:datatype,...paramn:datatype):returnType;
}

where SomeName is the name of the interface, method1, ...methodn are the methods in the interface, param1:datatype, ...paramn:datatype are the parameters of the methods, and returnType is the datatype of each method's return value.

Warning

In interfaces, method declarations do not (and must not) include curly braces. The following method declaration causes a compile-time error in an interface because it includes curly braces:

function method1 (param:datatype):returnType {
}

The error generated is:

Methods defined in an interface must not have a body.

All methods declared in an interface must not include an access-control modifier. Variable definitions are not allowed in ActionScript interfaces; neither can interface definitions be nested. However, interfaces can include get and set methods, which can be used to simulate variables (from the perspective of the code using the methods). Like class definitions, interface definitions can be placed directly within a package statement or outside of any package statement, but nowhere else.

As we saw in the preceding section, a class that wishes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required