----- Original Message ----- From: "markgoldin_2000" <[EMAIL PROTECTED]> To: <flexcoders@yahoogroups.com> Sent: Friday, November 07, 2008 6:17 PM Subject: [flexcoders] Re: removeEventListener
> Yes, parent listener will get it, and that is my understanding of > working with custom events. A child adds a custom event to its parent, > and then when custom event is dispatched the parent pushes it back to > this child for processing. Am I totally wrong about custom events? :( LOL, sort of. Any component can create and dispatch an event. If the event bubbles it's passed up the display tree and handlers attached to any intervening component will pick up the event. It doesn't have to be handled by the parent and the handler code doesn't have to be handled by the child - it usually isn't. I'd check out the excellent flex in a week video course - for a better explanation than my poor one (event handling involves much more than I said). There's load of other event tutorials around too. My quest for a small example -in full- was so that we can see exactly how you are trying to work and what you are trying to achieve, without second guessing the code we can't see. Paul > > --- In flexcoders@yahoogroups.com, Alex Harui <[EMAIL PROTECTED]> wrote: >> >> I think Paul is saying that your example didn't do what you said it > would do. It seems to leave a listener on the parent, and because > your custom event has bubbling=true, the parent listener will get it >> >> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] > On Behalf Of markgoldin_2000 >> Sent: Friday, November 07, 2008 10:04 AM >> To: flexcoders@yahoogroups.com >> Subject: [flexcoders] Re: removeEventListener >> >> >> I will try to get a sample. >> But what exactly are you asking for? >> I am showing how I am adding a custom event listener to a form's >> parent. And how the form then processes remote event. >> >> --- In > flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>, "Paul > Andrews" <paul@> wrote: >> > >> > >> > ----- Original Message ----- >> > From: "markgoldin_2000" <markgoldin_2000@> >> > To: > <flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>> >> > Sent: Friday, November 07, 2008 4:58 PM >> > Subject: [flexcoders] Re: removeEventListener >> > >> > >> > > Ok, I will try to show some code. >> > > Form's Init >> > > >> > > private function init():void >> > > { >> > > >> > > parent.removeEventListener("remoteDateEvent", > remoteClickHandler) >> > > parent.addEventListener("remoteDateEvent", remoteClickHandler) >> > > } >> > >> > The init function removes the listener then puts the same listener >> back - >> > it's totally pointless. >> > >> > > private function remoteClickHandler(event:remoteDateRun):void >> > > { >> > > // each form has different lineId. It would print twice when a >> second >> > > form dispatches custom event. Which is what I am fighting with. >> > > trace(lineId); >> > > runDate = event.runDate; >> > > dailyJobSumaryList(); >> > > } >> > >> > >> > > Before form is added I am removing all forms from Parent: >> > > reportParameters.removeAllChildren(); >> > > where reportParameters is "parent". >> > > >> > > >> > > My custom event object is this: >> > > public class remoteDateRun extends Event >> > > { >> > > public static var remoteDateEvent_SET:String = >> > > "remoteDateEvent"; >> > > public var runDate:String = new String(); >> > > public var lineId:int = 1; >> > > public function remoteDateRun(type:String, >> > > bubbles:Boolean=true, cancelable:Boolean=true) >> > > { >> > > super(type, bubbles, cancelable); >> > > } >> > > override public function clone():Event >> > > { >> > > return new remoteDateRun(remoteDateEvent_SET); >> > > } >> > > } >> > > >> > > custom event is dispatched like this: >> > > var eventObj:remoteDateRun = new > remoteDateRun("remoteDateEvent"); >> > > var df:DateFormatter = new >> > > DateFormatter(); >> > > df.formatString = >> > > "MM/DD/YYYY"; >> > > eventObj.runDate = >> > > df.format(date.selectedDate); >> > > dispatchEvent(eventObj); >> > >> > You've left out the most important part! >> > >> > The forms and the event handling.. >> > >> > Try and make a small example with the forms - it's always good to >> build a >> > small (complete) example to illustrate the problem. >> > >> > Paul >> > >> > >> > >> > >> > >> > > >> > > >> > > >> > > --- In > flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>, "Paul > Andrews" <paul@> wrote: >> > >> >> > >> ----- Original Message ----- >> > >> From: "markgoldin_2000" <markgoldin_2000@> >> > >> To: > <flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>> >> > >> Sent: Friday, November 07, 2008 4:26 PM >> > >> Subject: [flexcoders] removeEventListener >> > >> >> > >> >> > >> >I have spent some time trying to understand why >> removeEventListener >> > >> > would not remove an event listener. I have a Vbox that at run >> time >> > > I >> > >> > am adding a form to. In init of that form >> parent.addEventListener >> > > adds >> > >> > a listener to VBox. Then I am adding another form. That form > is >> > > based >> > >> > on same class as first form is. So it adds same listener. But >> > > fisrt it >> > >> > parent.removeEventListener. Now, second form dispatches an >> event >> > > the >> > >> > VBox listens to and I see that a handler of that event runs >> twice. >> > >> > Once for the current form, then for the previous form that > was >> > > removed >> > >> > from the VBox before I added second one. Can someone please >> > > explain >> > >> > why's that happening? >> > >> >> > >> A small code sample is worth a thousand words. >> > >> >> > >> > Thank you. >> > >> >> > > >> > > >> > > >> > > >> > > ------------------------------------ >> > > >> > > -- >> > > Flexcoders Mailing List >> > > FAQ: >> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt >> > > Alternative FAQ location: >> > > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469- >> 446f-b4cf-1e62079f6847 >> > > Search Archives: >> > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! >> Groups >> > > Links >> > > >> > > >> > > >> > >> > > > > > ------------------------------------ > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Alternative FAQ location: > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > Links > > >