User Guide
Adding custom properties and methods to a component 103
The simplest way to write StateComboBoxDirectRef.mxml is to use the
mx.core.Application.application static property to write the index directly to the
Te xt A rea control, as the following example shows:
<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/StateComboBoxDirectRef.mxml -->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
close="handleCloseEvent(event);">
<mx:Script>
<![CDATA[
import flash.events.Event;
import mx.core.Application;
public function handleCloseEvent(eventObj:Event):void {
mx.core.Application.application.myTAMain.text=
String(this.selectedIndex);
}
]]>
</mx:Script>
<mx:dataProvider>
<mx:String>AK</mx:String>
<mx:String>AL</mx:String>
</mx:dataProvider>
</mx:ComboBox>
In the previous example, you use the close event of the ComboBox control to write the
selectedIndex directly to the TextArea control in the main application. You must cast the
value of
selectedIndex to a String because the text property of the TextArea control is of
type String.