Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 115

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

Custom MXML components can implement interfaces just as other ActionScript classes can.
To do this, you use the
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
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.
attribute. All MXML tags support this attribute.
implements
attribute to point to its
implements
About interfaces
115

Advertisement

Table of Contents
loading

Table of Contents