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
TextArea
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.
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...