Look up event bubbling.

Essentially if you dispatch your event with bubble=true (the second
parameter to an Event constructor), then the event will 'bubble' all
the way up the display hierarchy. So your document class will only
have to listen to itself for a given event - if any of its children
dispatch that event, it'll be notified.

HTH,
   Ian

On Thu, Feb 5, 2009 at 7:14 PM, Lehr, Ross (N-SGIS) <ross.l...@lmco.com> wrote:
> This brings up a question I had about events.  Is there a way to send an 
> event all the way to the document class, no matter where it's been dispatched 
> from?  For instance, I have a document class that creates a "menu" class, 
> which creates several "icon button" classes.  I want the document class to be 
> able to receive the event dispatched from the "icon button".  Currently, the 
> only way I know how to do it is have the "icon button" send it to the "menu" 
> and then the "menu" send it to the document.  So, my question is, can the 
> document class receive an event directly sent from the "icon button"?
>
> Thanks,
> Ross
>
> -----Original Message-----
> From: flashcoders-boun...@chattyfig.figleaf.com 
> [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Merrill, Jason
> Sent: Thursday, February 05, 2009 1:03 PM
> To: Flash Coders List
> Subject: RE: [Flashcoders] Best way to access my main class?
>
>>>*Option 3:* I create a custom event, dispatch that event, and create a
>>>listener in MyGame rather than call a function directly.
>>>I'm guessing this is the best way to go theoretically, and will allow me to
>>>reuse my BouncingBall object in other applications, but it's a lot of extra
>>>code, and I constantly worry about not property cleaning up event listeners.
>
>
> Hands down, your option 3 is what you should do.  So what if it's some extra 
> code? It's the right way to accomplish this.  Your object should not target 
> and call methods in other classes outside of it, that's extremely tight 
> coupling, which is bad.
>
> So have your bouncing ball sprite dispatch a custom event, have the other 
> class listen for that same custom event and do whatever logic you want, like 
> call another method.  It's not messy if you keep your code clean.  It just 
> takes practice of doing this a lot before you realize an architecture emerges 
> in your coding you are familiar with.  I think its even messier to do option 
> 1 or 2, if that makes you feel any better.
>
>
> Jason Merrill
> Bank of America     Instructional Technology & Media   ยท   Learning 
> Performance Solutions L&LD
>
> Interested in Flash Platform technologies?  Join the Bank of America Flash 
> Platform Community
> Interested in innovative ideas in Learning?  Check out the Innovative 
> Learning Blog and subscribe.
>
>
>
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to