Adding custom properties and methods to a component
97
For more information, see
Chapter 3, “Using ActionScript to Create Components,” on
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) {
this.dataProvider=stateArrayShort; }
else {
this.dataProvider=stateArrayLong; }
}
// 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
shortNames
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.
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...