Interfaces
ActionScript 3.0 also allows you to define interfaces. Interfaces allow you to separate the interface from the implementation, which enables greater application flexibility.
Much of what you learned about declaring classes applies to declaring interfaces as well. In fact, it’s easier to list the differences:
Interfaces use the
interfacekeyword rather than theclasskeyword.Interfaces cannot declare properties.
Interface methods declare the method signature but not the implementation.
Interfaces declare only the
publicinterface for implementing classes, and therefore method signature declarations do not allow for modifiers.
By convention, interface names start with an uppercase I. The following is an example of an
interface:
package com.example {
public interface IExample {
function a():String;
function b(one:String, two:uint):void;
function get example():String;
function set example(value:String):void;
}
}In the preceding example, interface says that any implementing class must
declare methods a() and b() using the specified signatures.
You can declare a class so that it implements an interface using the implements keyword, following the class name or following the superclass name if
the class extends a superclass. The following example implements IExample:
package com.example { import com.example.IExample; public class Example implements IExample { private var _example:String; public function get example():String { return _example; } public function set example(value:String):void ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access