Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 96

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

Advertisement

The following example modifies the example in
ActionScript" on page 93
than an ActionScript variable definition:
<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/StateComboBoxPropMXML.mxml -->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="setNameLength();">
<!-- Control display of state names. -->
<mx:Boolean id="shortNames">true</mx:Boolean>
<mx:Script>
<![CDATA[
// Define private variables.
private var stateArrayShort:Array = ["AK", "AL"];
private var stateArrayLong:Array = ["Arkansas", "Alaska"];
// Define listener method.
public function setNameLength():void {
if (shortNames) {
else {
}
]]>
</mx:Script>
</mx:ComboBox>
In the preceding example, you implement the StateComboBox.mxml file by using the
tag to add a new property,
<mx:Boolean>
property controls whether the
format, or the entire state name.
Defining properties by using setters and getters
You can define properties for your MXML components by using setter and getter methods.
The advantage of getters and setters is that they isolate the variable from direct public access
so that you can perform the following tasks:
Inspect and validate any data written to the property on a write
Trigger events that are associated with the property when the property changes
Calculate a return value on a read
96
Creating Advanced MXML Components
to define the
shortNames
dataProvider=stateArrayShort; }
dataProvider=stateArrayLong; }
shortNames
ComboBox
control displays state names that use a two-letter
"Defining properties and methods in
property by using an MXML tag, rather
, with a default value of
. This
true

Advertisement

Table of Contents
loading

Table of Contents