You don't say what event you want to listen to from the Tree, but I'll
assume it's "change" from tree1.
 
The simplest way is to write
 
    <mx:Tree id="tree1" change="tree1_changeHandler(event)"/>
 
and
 
    private function tree1_changeHandler(event:Event):void
    {
        // do something to combo, such as set its dataProvider
    }
 
If for some reason you really want to use addEventListener(), you would
do
 
    tree1.addEventListener(Event.CHANGE, tree1_changeHandler);
 
inside your init() method.
 
Note that you call addEventListener() on the object which is dispatching
the event, not on the object that you want to be affected.
 
In both cases above, the listener is actually the application or
component that this code is inside of, not the ComboBox. The application
listens to the "change" event from tree1 and does something to combo1 in
response.
 
In order to make the ComboBox the listener, you would have to subclass
it and set one of its methods as a "change" handler for tree1. But this
wouldn't be the normal way to do it. In general, a component listens to
events from its children and responds by changing its state or the state
of other children.
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Persaud, Anthony
Sent: Friday, April 06, 2007 2:32 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Event Setup Question



Newbie here (sorry),

 

I'd like to setup a ComboBox (in one panel) listen to the user selecting
an item from a Tree (that is on another Panel component, but on the same
screen). However, there are two tree components in the app. Is there way
to have the ComboBox only listen to one of the trees and ignore the
other. Or how do I set it up? Example:

 

<mx:Script>

            <![CDATA[

 

public function init():void { //called on creationComplete of
Application

                        

combo.addEventListener( "what listener do I choose here for tree1",
myfunction);

 

}

            

            public function myfunction( e:TreeEvent ):void {

            //do stuff here

}

 

            ]]>

 </mx:Script>

 

 

<mx:Panel>

<mx:ComboBox id="combo" />

</mx:Panel>

 

<mx:Panel>

<mx:Tree id="tree1" />

</mx:Panel>

 

<mx:Panel>

<mx:Tree id="tree2" />

</mx:Panel>

 

 

Thanks ahead of time,


Anthony

 

Reply via email to