User Guide

104 Creating Advanced MXML Components
You could make the custom component slightly more reusable by using the parentDocument
property to reference the TextArea control, rather than the
mx.core.Application.application static property. By using the parentDocument
property, you can call the custom component from any other MXML component that
contains a TextArea control named myTAMain, as the following example shows:
<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/StateComboBoxDirectRefParentObj.mxml -->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
close="handleCloseEvent(event);">
<mx:Script>
<![CDATA[
import flash.events.Event;
public function handleCloseEvent(eventObj:Event):void {
parentDocument.myTAMain.text=String(selectedIndex);
}
]]>
</mx:Script>
<mx:dataProvider>
<mx:Array>
<mx:String>AK</mx:String>
<mx:String>AL</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
Although these examples work, they require that the Te xt A re a control has a predefined id
property, and that MXML component knows that id. In this case, custom component is an
example of a tightly coupled component. That is, the component is written for a specific
application and application structure, and it not easily reused in another application.