03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

interface statement<br />

interface InterfaceName [extends InterfaceName ] {}<br />

Defines an interface. An interface is similar to a class, with the following important<br />

differences:<br />

■ Interfaces contain only declarations of methods, not their implementation. That is, every<br />

class that implements an interface must provide an implementation for each method<br />

declared in the interface.<br />

■ Only public members are allowed in an interface definition; instance <strong>and</strong> class members<br />

are not permitted.<br />

■ The get <strong>and</strong> set statements are not allowed in interface definitions.<br />

Availability: <strong>ActionScript</strong> <strong>2.0</strong>; Flash Player 6<br />

Example<br />

The following example shows several ways to define <strong>and</strong> implement interfaces:<br />

(in top-level package .as files Ia, B, C, Ib, D, Ic, E)<br />

// filename Ia.as<br />

interface Ia {<br />

function k():Number; // method declaration only<br />

function n(x:Number):Number; // without implementation<br />

}<br />

// filename B.as<br />

class B implements Ia {<br />

function k():Number {<br />

return 25;<br />

}<br />

function n(x:Number):Number {<br />

return x + 5;<br />

}<br />

} // external script or Actions panel // script file<br />

var mvar:B = new B();<br />

trace(mvar.k()); // 25<br />

trace(mvar.n(7)); // 12<br />

// filename c.as<br />

class C implements Ia {<br />

function k():Number {<br />

return 25;<br />

}<br />

} // error: class must implement all interface methods<br />

// filename Ib.as<br />

interface Ib {<br />

function o():Void;<br />

}<br />

222 <strong>ActionScript</strong> language elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!