User Guide

About interfaces 115
Custom MXML components can implement interfaces just as other ActionScript classes can.
To do this, you use the
implements attribute. All MXML tags support this attribute.
The following code is an example of a simple interface that declares several methods:
// The following is in a file named SuperBox.as.
interface SuperBox {
function selectSuperItem():String;
function removeSuperItem():Boolean;
function addSuperItem():Boolean;
}
A class that implements the SuperBox interface uses the implements attribute to point to its
interface and must provide an implementation of the methods. The following example of a
custom ComboBox component implements the SuperBox interface:
<?xml version="1.0"?>
<!-- StateComboBox.mxml -->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
implements="SuperBox">
<mx:Script>
<![CDATA[
public function selectSuperItem():String {
return "Super Item was selected";
}
public function removeSuperItem():Boolean {
return true;
}
public function addSuperItem():Boolean {
return true;
}
]]>
</mx:Script>
<mx:dataProvider>
<mx:String>AK</mx:String>
<mx:String>AL</mx:String>
</mx:dataProvider>
</mx:ComboBox>
You can implement multiple interfaces by separating them with commas, as the following
example shows:
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
implements="SuperBox, SuperBorder, SuperData">
All methods that you declare in an interface are considered public. If you define an interface
and then implement that interface, but do not implement all of its methods, the MXML
compiler throws an error.