Simple event bubbling in AS2

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.

Comments