Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 105

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

Advertisement

Passing a reference to the component
A loosely coupled component is a highly reusable component that you can easily use in
different places in one application, or in different applications. To make the component from
"Supporting data binding in custom properties" on page 99
to the
TextArea
control to the custom component, as the following example shows:
<?xml version="1.0"?>
<!-- mxmlAdvanced/MainPassRefToTA.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<mx:TextArea id="myTAMain" />
<MyComp:StateComboBoxPassRefToTA outputTA="{myTAMain}" />
</mx:Application>
The custom component does not have to know anything about the main application, other
than that it writes its results back to a
<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/StateComboBoxPassRefToTA.mxml -->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
close="handleCloseEvent(event);">
<mx:Script>
<![CDATA[
import flash.events.Event;
import mx.controls.TextArea;
// Define a variable of type mx.controls.TextArea.
public var outputTA:TextArea;
public function handleCloseEvent(eventObj:Event):void {
outputTA.text=String(this.selectedIndex);
}
]]>
</mx:Script>
<mx:dataProvider>
<mx:String>AK</mx:String>
<mx:String>AL</mx:String>
</mx:dataProvider>
</mx:ComboBox>
In this example, you use the Flex data binding syntax to pass the reference to the TextArea
control to your custom component. Now, you can use StateComboBoxPassRefToTA.mxml
anywhere in an application. The only requirement is that the calling component must pass a
reference to a TextArea control to the component.
TextArea
control, as the following example shows:
Adding custom properties and methods to a component
reusable, you can pass a reference
105

Advertisement

Table of Contents
loading

Table of Contents