Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 97

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

Advertisement

For more information, see
page
25.
In the following example, the StateComboBoxGetSet.mxml component contains several new
properties and methods:
<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/StateComboBoxSetGet.mxml -->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
// Define private variables.
private var stateArrayShort:Array = ["AK", "AL"];
private var stateArrayLong:Array = ["Arkansas", "Alaska"];
// Variable holding the display setting.
private var __shortNames:Boolean = true;
// Set method.
public function set shortNames(val:Boolean):void {
// Call method to set the dataProvider
// based on the name length.
__shortNames = val;
if (__shortNames) {
else {
}
// Get method.
public function get shortNames():Boolean{
return __shortNames;
}
]]>
</mx:Script>
</mx:ComboBox>
In this example, you create a StateComboBoxGetSet.mxml control that takes a
property defined by using ActionScript setter and getter methods. One advantage to using
setter and getter methods to define a property is that the component can recognize changes to
the property at run time. For example, you can give your users the option of displaying short
state names or long state names from the application. The setter method modifies the
component at run time in response to the user's selection.
Chapter 3, "Using ActionScript to Create Components," on
this.dataProvider=stateArrayShort; }
this.dataProvider=stateArrayLong; }
Adding custom properties and methods to a component
shortNames
97

Advertisement

Table of Contents
loading

Table of Contents