If you don't want a dependency on the target property of the event object, then you could check the className instead (so you can be sure it was a _button_ that dispatched the click event versus some other component. BTW, you can also use addEventListener to use the same handler for multiple events rather than the handleEvent method. Sample below.
 
hth,
matt horn
flex docs
 
------sample--------
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" initialize="createListeners()" >
 <mx:Script><![CDATA[
  function createListeners() {
   button1.addEventListener("click", eventListener);
   cb1.addEventListener("click", eventListener);
  }
 
  function eventListener(event) {
   if (event.target.className == "Button") {
    // Perform search.
   } else if (event.target.className == "CheckBox") {
    // Modify search to include all words.    
   }   
  }

 ]]></mx:Script>
 <mx:Button label="Submit" id="button1" />
 <mx:CheckBox label="All Words" id="cb1" />
 <mx:TextArea id="ta1" text="Please enter a search term" width="200" />
</mx:Application>


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jesus Salvador Ramos Cardona
Sent: Friday, April 22, 2005 6:53 PM
To: [email protected]
Subject: RE: [flexcoders] About single methd handling mutiple events.

Thanks, Abdul.

 

That’s what I thought I’d do, and it looks like this.

 

        public function handleEvent(eventObj:Object):Void {
               var type = eventObj.type;
               var target = eventObj.target.className; 
               if (type=="click" && target == “button”) {
                       // I do not want to be dependant on my component’s name!!!!!
                       showTitleView(myDataGridName.selectedItem); 
               }
               else if (type==”cellPress” && target == “myDataGridName”) {
                       // Like this, where I do not depend on the component’s name to call the same 
                       // method.
                       showTitleView(target.selectedItem);
               }
        }

 

But this way I must rely on my component’s id to call the same method if the event is fired with the button’s click. I wonder if there’s a way to avoid this dependency

 

Any ideas?

 

J.

 


De: [email protected] [mailto:[email protected]] En nombre de Abdul Qabiz
Enviado el: Vier
nes, 22 de Abril de 2005 05:29 pm
Para: [email protected]
Asunto: RE: [flexcoders] About single methd handling mutiple events.
Importancia: Alta

 

Hi,

you can define a handleEvent(..) function in your application(mail.mxml),
this method would be called whenever an event happen.

Look at the "Defining the handleEvent() method"  section in Flex docs for
more: http://livedocs.macromedia.com/flex/15/flex_docs_en/00000503.htm

Hope that helps

-abdul



________________________________

From: [email protected] [mailto:[email protected]]
Sent: Saturday, April 23, 2005 3:38 AM
To: [email protected]
Subject: [flexcoders] About single methd handling mutiple events.



Hey.



What's the best way to have a single method respond to both a clic event
from a button, and a cellPress event from a DataGrid?

Both components are inside the mail mxml.



Thanks for your help.



J.


________________________________

Yahoo! Groups Links


*      To visit your group on the web, go to:
      http://groups.yahoo.com/group/flexcoders/
       
*      To unsubscribe from this group, send an email to:
      [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
       
*      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .






Yahoo! Groups Links

Reply via email to