Chapter 7: Creating Simple Mxml Components - Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual

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

Advertisement

For example, Flex supplies a ComboBox control that you can use as part of a form that
collects address information from a customer. You can use a ComboBox to let the user select
the State portion of the address from a list of the 50 states in the U.S. In an application that
has multiple locations where a user can enter an address, it would be tedious to create and
initialize multiple ComboBox controls with the information about all 50 states.
Instead, you create an MXML component that contains a ComboBox control with all 50
states defined within it. Then, wherever you must add a state selector to your application, you
use your custom MXML component.
Creating MXML components
An application that uses MXML components includes a main MXML application file, which
contains the
<mx:Application>
defined in separate MXML and ActionScript files. Each MXML component extends an
existing Flex component, or another MXML component.
You create an MXML component in an MXML file where the component's filename becomes
its MXML tag name. For example, a file named StateComboBox.mxml defines a component
with the tag name of
The root tag of an MXML component is a component tag, either a Flex component or
another MXML component. The root tag specifies the http://www.adobe.com/2006/mxml
namespace. For example, the following MXML component extends the standard Flex
ComboBox
control.
<?xml version="1.0"?>
<!-- mxml/StateComboBox.mxml -->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:dataProvider>
<mx:String>AK</mx:String>
<mx:String>AL</mx:String>
<!-- Add all other states. -->
</mx:dataProvider>
</mx:ComboBox>
As part of its implementation, a custom MXML component can reference another custom
MXML component.
78
Creating Simple MXML Components
root tag, and references one or more components that are
.
<StateComboBox>

Advertisement

Table of Contents
loading

Table of Contents