[flexcoders] Re: Custom Events
I have listed my setup below. Results: I have confirmed that the initialize event on the parent object adds the event. Clicking the item on the grid, fires the internal handler and I have confirmed that it dispatches the custom event. However, the parent event handler for the custom event does not fire. My call to the custom component looks like this: pdb:CategoriesPnl id=CategoriesPnl initialize=CategoriesPnl.CtgsPnlDG.addEventListener('dgItemClick', CtgsPnlDGItemClick);/pdb:CategoriesPnl The eventhandler in the parent looks like this: private function CtgsPnlDGItemClick(event:ListEvent):void {Alert.show(event.eventPhase+'_external');} The custom component looks like this: mx:Panel xmlns:mx=http://www.adobe.com/2006/mxml; label=Categories backgroundColor=#CC width=100% height=100% mx:Script ![CDATA[ import flash.events.Event; import mx.collections.ArrayCollection; import mx.controls.DataGrid; import mx.controls.Alert; import mx.events.* import mx.events.ListEvent [Bindable] public var CtgsPnlAC:ArrayCollection = new ArrayCollection; private function CtgsPnlDGItemClick(event:ListEvent):void { Alert.show('internal'); Alert.show('dispatch result'+dispatchEvent(new Event (dgItemClick,true)).toString()); } private function CtgsPnlDGRefresh():void { CtgsPnlWebSvcVO.GetAllCategories(); } ]] /mx:Script mx:Metadata [Event(name=dgItemClick, type=mx.events.ListEvent.ITEM_CLICK)] /mx:Metadata mx:WebService id=CtgsPnlWebSvcVO wsdl=http://support07:57773/csp/prtest/pdb.sl.WebServiceVO.cls? WSDL=1 mx:operation name=GetAllCategories resultFormat=object fault=mx.controls.Alert.show(event.fault.faultString) result=CtgsPnlAC = event.result.Categories; /mx:operation /mx:WebService mx:DataGrid id=CtgsPnlDG height=100% dataProvider={CtgsPnlAC} initialize=CtgsPnlDGRefresh() itemClick=CtgsPnlDGItemClick(event) mx:columns mx:DataGridColumn headerText=ID dataField=CtgId/ mx:DataGridColumn headerText=Key dataField=CtgKey/ /mx:columns /mx:DataGrid /mx:Panel --- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote: ...firing an handler off the itemSelect event and then in the handler creating a new event and dispatching that to an external handler That is how I do it. What didn't work? Tracy
RE: [flexcoders] Re: Custom Events
Looks ok to me. The event is bubbling, so try listening for the event at the Main app level: this.addEventListener('dgItemClick', CtgsPnlDGItemClick) Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of rss181919 Sent: Wednesday, August 06, 2008 3:38 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Custom Events I have listed my setup below. Results: I have confirmed that the initialize event on the parent object adds the event. Clicking the item on the grid, fires the internal handler and I have confirmed that it dispatches the custom event. However, the parent event handler for the custom event does not fire. My call to the custom component looks like this: pdb:CategoriesPnl id=CategoriesPnl initialize=CategoriesPnl.CtgsPnlDG.addEventListener('dgItemClick', CtgsPnlDGItemClick);/pdb:CategoriesPnl The eventhandler in the parent looks like this: private function CtgsPnlDGItemClick(event:ListEvent):void {Alert.show(event.eventPhase+'_external');} The custom component looks like this: mx:Panel xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml label=Categories backgroundColor=#CC width=100% height=100% mx:Script ![CDATA[ import flash.events.Event; import mx.collections.ArrayCollection; import mx.controls.DataGrid; import mx.controls.Alert; import mx.events.* import mx.events.ListEvent [Bindable] public var CtgsPnlAC:ArrayCollection = new ArrayCollection; private function CtgsPnlDGItemClick(event:ListEvent):void { Alert.show('internal'); Alert.show('dispatch result'+dispatchEvent(new Event (dgItemClick,true)).toString()); } private function CtgsPnlDGRefresh():void { CtgsPnlWebSvcVO.GetAllCategories(); } ]] /mx:Script mx:Metadata [Event(name=dgItemClick, type=mx.events.ListEvent.ITEM_CLICK)] /mx:Metadata mx:WebService id=CtgsPnlWebSvcVO wsdl=http://support07:57773/csp/prtest/pdb.sl.WebServiceVO.cls? http://support07:57773/csp/prtest/pdb.sl.WebServiceVO.cls? WSDL=1 mx:operation name=GetAllCategories resultFormat=object fault=mx.controls.Alert.show(event.fault.faultString) result=CtgsPnlAC = event.result.Categories; /mx:operation /mx:WebService mx:DataGrid id=CtgsPnlDG height=100% dataProvider={CtgsPnlAC} initialize=CtgsPnlDGRefresh() itemClick=CtgsPnlDGItemClick(event) mx:columns mx:DataGridColumn headerText=ID dataField=CtgId/ mx:DataGridColumn headerText=Key dataField=CtgKey/ /mx:columns /mx:DataGrid /mx:Panel --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Tracy Spratt [EMAIL PROTECTED] wrote: ...firing an handler off the itemSelect event and then in the handler creating a new event and dispatching that to an external handler That is how I do it. What didn't work? Tracy
[flexcoders] Re: Custom Events
I modified the call as follows: pdb:CategoriesPnl id=CategoriesPnl initialize=CtgsPnlInit (event);/pdb:CategoriesPnl private function CtgsPnlInit(event:Event): void { this.addEventListener('dgItemClick', CtgsPnlDGItemClick) Alert.show(this.hasEventListener(dgItemClick).toString()); } Results: 1. On entering the custom panel at runtime, the alert return 'true' indicating that the listener was added to 'this'. 2. On selectItem call, the alert message ' dispatch result: true' and then the message 'internal' is displayed. However, the alert message 'external' never displays (which should follow the 'internal' message).