User Guide

Creating custom components 21
The StateComboBox.mxml file specifies the ComboBox control as its root tag, so you can
reference all of the properties of the ComboBox control in the MXML tag of your custom
component, or in the ActionScript specified in an
<mx:Script> tag. For example, the
following example specifies the
ComboBox.rowCount property and a listener for the
ComboBox.close event for your custom control:
<?xml version="1.0"?>
<!-- intro/MyApplicationProperties.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<mx:Script>
<![CDATA[
import flash.events.Event;
private function handleCloseEvent(eventObj:Event):void {
// ...
}
]]>
</mx:Script>
<MyComp:StateComboBox rowCount="5" close="handleCloseEvent(event);"/>
</mx:Application>
For more information on MXML components, see “Creating Simple MXML Components
on page 77.
Creating ActionScript components
You create ActionScript components by defining ActionScript classes. You can create the
following types of components in ActionScript:
User-interface, or visual, components User-interface components contain both
processing logic and visual elements. You create custom user-interface components to modify
existing behavior or add new functionality to the component. These components usually
extend the Flex component hierarchy. You can extend from the UIComponent class, or any of
the Flex components, such as Button, ComboBox, or DataGrid. Your custom ActionScript
component inherits all of the methods, properties, events, styles, and effects of its superclass.
Nonvisual components Nonvisual components define nonvisual elements. Flex includes
several types of nonvisual components that you can create, including formatters, validators,
and effects. You create nonvisual components by creating a subclass from the Flex component
hierarchy. For validators, you create subclasses of the Validator class; for formatters you create
subclasses of the Formatter class; and for effects, you create subclasses of the Effect class.