Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 93

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

Advertisement

Defining properties and methods in ActionScript
With ActionScript, you define properties and methods by using the same syntax that you use
in an ActionScript class. For more information on using ActionScript to define properties and
methods, see
Chapter 3, "Using ActionScript to Create Components," on page
When using ActionScript, you place a property or method definition within an
block. The
<mx:Script>
file. A public variable declaration or a set function in an
of the component. A public ActionScript function in an
of the component.
In the following example, the component defines two data providers to populate the
ComboBox
control, and a function to use as the event listener for the
event. This function sets the data provider of the ComboBox based on the value of the
property. By default, the
shortNames
letter names:
<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/StateComboBoxPropAS.mxml -->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="setNameLength();">
<mx:Script>
<![CDATA[
// Define public variables.
public var shortNames:Boolean = true;
// 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>
tag must be an immediate child tag of the root tag of the MXML
shortNames
dataProvider=stateArrayShort; }
dataProvider=stateArrayLong; }
Adding custom properties and methods to a component
tag becomes a property
<mx:Script>
tag becomes a method
<mx:Script>
creationComplete
property is set to
true
25.
<mx:Script>
, to display two-
93

Advertisement

Table of Contents
loading

Table of Contents