What Kelly shows is the easiest way if you are doing only a few calls.

 

If you need to access the combo box selectedItem often, or access its properties, then you can pass a reference to the combo box itself into the child component. 

In the parent:

            <MyComponent1 id=”myC1” cboCvca=”{this.typeCvca }”

In the child component script block:

public var cboCvca:mx.controls.ComboBox;

Now you can say:

            var myValue:String = cboCvca.selectedItem.data;

Or:

            <mx:Text text={ cboCvca.selectedItem.data } …

 

If you need to access or bind to multiple controls, functions or variables from within a child component, you can pass a reference to the entire parent scope into the subcomponent.

In the parent:

            <MyComponent1 id=”myC1” cboCvca=”{this}” …

In the child component script block:

public var myParent:ParentComponentClassName;  //In the case of the top application level, use the application file name

Now you can say:

            var myValue:String = myParent.cboCvca.selectedItem.data;

var myValue:String = myParent.myVariable;

var myValue:String = myParent.myFunction();

Or:

            <mx:Text text={ myParent.cboCvca.selectedItem.data } …

 

 

Tracy


From: [email protected] [mailto:[email protected]] On Behalf Of Kelly
Sent: Wednesday, September 21, 2005 11:59 PM
To: [email protected]
Subject: RE: [flexcoders] Re: Access to parent control in parent component

 

 

 function changeSelection(event) {

            mychildComponent.someObjectVar = event.target.selectedItem;

}

 

 

 


From: [email protected] [mailto:[email protected]] On Behalf Of Ghislain Simard
Sent: Wednesday, September 21, 2005 10:34 PM
To: [email protected]
Subject: [flexcoders] Re: Access to parent control in parent component

 

Quote: "pass a reference to it into the component."

my parentDocument value that I would like to pass is from a
ComboBox.  How can I pass the selectedItem to the child component:

parent Component:
<mx:ComboBox id="typeCvca" dataProvider="{typeCombo.fr.system}"
change="changeSelection(event);changeCompBehav(event)"/>

thanks

--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]>
wrote:
> Try:
> parentDocument.comp1.selectedItem.data
>
> Or, if you are going to do a lot with the parent component, pass a
> reference to it into the component.  Be sure to type the
declaration
> explicitly if you plan to bind through the reference.
>
> Tracy
>
> -----Original Message-----
> From: [email protected]
[mailto:[email protected]] On
> Behalf Of Ghislain Simard
> Sent: Wednesday, September 21, 2005 4:10 PM
> To: [email protected]
> Subject: [flexcoders] Access to parent control in parent component
>
> If I want to get the value of a ComboBox's selectedItem coming
from the
> parent component.  How to do so?
>
>
> I've tried this without success:
> switch (_parent.comp1.selectedItem.data){
>   case 1:
>           do this...
>           break;
>   case 2:
>           do that...
>           break;
> }
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to