Macromedia flex 2 Manual
98
Creating Advanced MXML Components
You can also define events to be dispatched when a property changes. This enables you to
signal the change so that an event listener can recognize the change. For more information on
events, see
signal the change so that an event listener can recognize the change. For more information on
events, see
.
You can call a component’s custom methods and access its properties in ActionScript just as
you would any instance method or component property, as the following application shows:
you would any instance method or component property, as the following application shows:
<?xml version="1.0"?>
<!-- mxmlAdvanced/MainPropSetGet.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<!-- mxmlAdvanced/MainPropSetGet.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:StateComboBoxSetGet id="myStateCB" shortNames="true"/>
<mx:Button click="myStateCB.shortNames=!myStateCB.shortNames;"/>
</mx:Application>
<mx:Button click="myStateCB.shortNames=!myStateCB.shortNames;"/>
</mx:Application>
In this example, selecting the button toggles the display format of the state name between the
short and long formats.
short and long formats.
Defining inspectable properties
You should precede the variable or set function with the
[Inspectable]
metadata tag if you
plan to use the component in an authoring tool such as Adobe Flex Builder. The
[Inspectable]
metadata tag must immediately precede the property’s variable declaration or
the setter and getter methods to be bound to that property, as the following example shows:
<mx:Script>
<![CDATA[
// Define public variables.
[Inspectable(defaultValue=true)]
public var shortNames:Boolean = true;
[Inspectable(defaultValue=true)]
public var shortNames:Boolean = true;
]]>
</mx:Script>
For more information on the
[Inspectable]
metadata tag, see
.