Skip navigation
ilya_k
Currently Being Moderated

Flex events: when to use capture phase

Sep 1, 2010 4:48 PM

Greetings!

 

I seem to understand Event flow (maybe I do not) but  have difficulties to figure out 

why should I use capture phase event in adddEventListener? Anyone can think of use case?

Why would I create custom event with capture not bubbling as default?

 

Regards

 
Replies
  • Currently Being Moderated
    Sep 1, 2010 5:13 PM   in reply to ilya_k

    Bubbling events is generally a bad practice.  Bubbling should be reserved

    for events that can be dispatched my more than one children of varying types

    within a container.  That's why only things like adding/removing children,

    mouse and keyboard activity and focus bubble.

     

    Capture is used by a container to react to an event and possibly prevent the

    actual target's listeners from seeing it.  It's primary use is in handling

    mouse dragging, similar to the MouseCapture() API in Windows.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 1, 2010 9:49 PM   in reply to Flex harUI

    Alex, why is bubbling events considered bad practice?  I am really curious because I make heavy use of bubbling to send information to the systemManager to act as a controller.

     

    Also seems useful to me as a way to more loosely couple components.  But, I am not trying to be combative or defensive, just explaining why I use bubbling.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 1, 2010 10:17 PM   in reply to supersonicecho

    Because every level of the display tree gets to see the event, and it

    requires that you come up with unique event names.  It essentially breaks

    encapsulation and takes longer to process.

     

    You might want to look at how other application frameworks set up their

    controllers.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 1, 2010 10:43 PM   in reply to Flex harUI

    Thanks for the explanation.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 2, 2010 1:49 PM   in reply to ilya_k

    APPLICATION_COMPLETE is only dispatched from the Application and

    SystemManager.  If you are not listening there you won't see it.

     

    Note that, if you had a sub-app that bubbled APPLICATION_COMPLETE, the

    main-app would see it and potentially run its APPLICATION_COMPLETE handlers

    again, which is probably not desirable.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 2, 2010 10:41 PM   in reply to ilya_k

    There is no capture phase at the target.  It makes more sense to listen to

    the sub-app than one of its parents.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 3, 2010 9:54 AM   in reply to ilya_k

    It matters, as there is no capture phase at the target.  If you are

    listening to the systemManager, you must use false.  Using true will work in

    this case because the child application also dispatches the event, but it

    would not work in the general case

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points