Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 106

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 calling component
In
"Passing a reference to the component" on page
component to the custom MXML component. This allowed the MXML component to access
only a single component in the main application.
One type of reference that you can pass to your component is a reference to the calling
component. With a reference to the calling component, your custom MXML file can access
any properties or object in the calling component.
To pass a reference to the calling component to a custom MXML component, you create a
property in the custom MXML component to represent the calling component. Then, from
the calling component, you pass a reference to the calling component to the custom MXML
component, as the following example shows:
<?xml version="1.0"?>
<!-- mxmlAdvanced/CallingComponent.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="left"
xmlns:MyComp="myComponents.*">
<!-- Use the caller property to pass a reference to the
calling component to DestinationComp. -->
<mx:Label text="Enter text"/>
<mx:TextInput id="text1" text="Hello"/>
<mx:Label text="Input text automatically copied to MXML component."/>
<MyComp:DestinationComp caller="{this}"/>
</mx:Application>
In the definition of DestinationComp.mxml, you define the
its data type the name of the file of the calling MXML file, as the following example shows:
<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/DestinationComp.mxml -->
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
// Define variable to reference calling file.
[Bindable]
public var caller:CallingComponent;
]]>
</mx:Script>
<mx:TextInput id="mytext" text="{caller.text1.text}"/>
</mx:VBox>
106
Creating Advanced MXML Components
105, you passed a reference to a single
property, and specify as
caller

Advertisement

Table of Contents
loading

Table of Contents