Hi, This kind of problem can be solved by using Model-View-Controller approach which allows loose coupling between view and controller. I think, Cairngorm frameworks solves such problems by providing View, ViewHelper & Command classes. I don't know much of the framework, but you might want to look at it once. You can search flexcoders archives for any queries, there has been many discussions on this list. http://www.richinternetapps.com/archives/000094.html
> How can I have a button's click trigger the same event as my Grid's cellPress, given the following code? Do you mean, execute same code on Button's click and cellPress's doubleClick. Well you can decouple this by using Observer pattern i.e. by broadcasting common event. You can broadcast another event on both occasion (click and cellPress), this event is subscribed by a listener which then gets the details. So it solves the purpose of keeping logic at one place... -abdul ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] Sent: Saturday, April 23, 2005 5:45 AM To: [email protected] Subject: RE: [flexcoders] About single methd handling mutiple events. Abdul, Since my flex app is a prototype, components will surely change names and types, so I am required to have enough flexibility of code and components. Bottom Line: How can I have a button's click trigger the same event as my Grid's cellPress, given the following code? Button: <mx:Button id="btnViewDetail" label="Ver Detalle" click="showLiquidationDetail();"/> DataGrid: <mx:DataGrid id="liquidationRequestsGrid" dataProvider="{mx.utils.ArrayUtil.toArray(liquidationsModel.liquidation)}" cellPress="handleDoubleClick(event);" width="100%"> Functions: public function showLiquidationDetail(Void):Void { var selectedItem:Object = liquidationRequestsGrid.selectedItem; getLiquidationDetail(selectedItem); } public function handleDoubleClick(event:Object):Void { if (event.target.selectedItem != undefined || event.target.selectedItem.length == 1) { if(handler.detectDoubleClick()) { getLiquidationDetail(event.target.selectedItem); } } else { alert("S�lo es posible ver el detalle de una sola liquidaci�n.", "Alerta", Alert.OK, undefined, undefined, errorImg); } } Is there a way to have the same event object in both methods, so that I can get rid of the grid reference in showLiquidationDetail method? Hope I'm explaining myself. J. ________________________________ De: [email protected] [mailto:[EMAIL PROTECTED] En nombre de Abdul Qabiz Enviado el: Viernes, 22 de Abril de 2005 06:14 pm Para: [email protected] Asunto: RE: [flexcoders] About single methd handling mutiple events. Importancia: Alta Hi, > I wonder if there's a way to avoid this dependency May be, what exactly is your requirement? -abdul ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] Sent: Saturday, April 23, 2005 4:23 AM 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: Viernes, 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 * 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 * 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 <*> 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] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

