7 Jan 2006

Ralf Bokelberg has a very elegant and simple method for bubbling events in AS2 that adds a bubbling aspect to objects that have had the EventDispatcher methods mixed in.

This should especially be of interest to those of you building Flash/Flex 1.5 applications with Arp.

In some instances, I actually believe that using manual bubbling (re-dispatching an event manually) adds semantic value to the event. Take, for example, a scenario where a button's "click" event were to bubble to the topmost Application form. It wouldn't have much meaning and you would have to include conditional logic based on the event target to determine what to do in response. This, of course, would give your Application form intimate knowledge of the inner structure of a child form, perhaps several levels removed, making your application fragile. Instead, the form containing the button can manually bubble the event, changing it in the process from a generic "click" event to an "ContactFormSubmit" event -- and thereby adding domain-specific meaning to the event. This new event can then be automatically bubbled from there on and handlers at any level could respond to it without intimate knowledge of the event target.

Creative Commons LicenseThe Simple event bubbling in AS2 article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.

Add Your Comment

Spam Protection by WP-SpamFree

Simple event bubbling in AS2

  1. Is that link supposed to lead me back to this same page?

    Nielz
  2. or should it link: here ?

    nielz
  3. Hi Nielz — thanks for letting me know. I have to stop doing that (forgetting to put the actual link in!) :)

    aral
  4. Hi Aral,

    Just wanted to share with you that we just had a brief conversation in a team about supporting event bubbling in Flex 1.5 and how we are going to deal with event bubbling in Flex 2 ( supported by Flex framework, for granted).

    And we had selected approach for event bubbling exactly the one that you had described in your blog and only then I found your blog entry.

    Although, we have a question to you regarding the usage of event bubbling in AS3.

    Generic Event class has a read-only “bubbles” property in Flex 2 UI framework.

    Documentation doc is here:
    http://livedocs.macromedia.com/labs/1/flex20beta3/langref/flash/events/Event.html

    We had spotted, that the constructor of Event expects “bubble” property as parameter:
    ————–
    Event(type:String, bubbles:Boolean = false, cancelable:Boolean = false)

    Creates an Event object to pass as a parameter to event listeners.
    ————–

    Does this mean that we can set “bubbles” property to FALSE or TRUE when creating new instance of the event?

    JabbyPanda