Creating Custom 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

Creating custom components

You create custom components as either MXML or ActionScript files. This section contains
an overview of both methods.
Creating MXML components
Flex supplies a
ComboBox
information from a customer. In the form, you can include a ComboBox control 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 forms where a user can enter an address, it would be tedious to
create and initialize multiple ComboBox controls with the same information about all 50
states.
Instead, you create an MXML component that contains a ComboBox control with all the 50
states defined within in it. Then, wherever you need to add a state selector to your
application, you use your custom MXML component. The following example shows a
possible definition for a custom ComboBox control:
<?xml version="1.0"?>
<!-- intro\StateComboBox.mxml -->
<!-- Specify the root tag and namespace. -->
<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>
This example shows the following:
The first line of the custom MXML component definition specifies the declaration of the
1.
XML version.
The first MXML tag of the component, called its root tag, specifies a Flex component or a
2.
custom component. MXML components correspond to ActionScript classes, therefore, the
root tag specifies the superclass of the MXML component. In this example, the MXML
component specifies the Flex ComboBox control as its superclass.
The
property in the root tag specifies the Flex XML namespace. In this example, the
3.
xmlns
property indicates that tags in the MXML namespace use the prefix mx:.
xmlns
The remaining lines of the component specify its definition.
4.
control that you can use as part of a form that collects address
Creating custom components
19

Advertisement

Table of Contents
loading

Table of Contents