« Microsoft just don't care... | Main | Inspectable metadata »

Should I Bubble?

Working on a fun AS3 project now, where I'll make some UI components. The components has several events that they want to notify the world about, but I'd love some help on a design decision: should the events dispatched from a component bubble per default?

A word from our sponsors :)

Comments

For low-level events, yes. All Mouse events, save rollover, rollout, bubble by default. So, you can "hear" about a click event 50 billion nested MovieClip's deep.

The problem is that has no strong-typing. Meaning, you can add an event listener with no guarentee that said component will ever dispatch it.

Using [Event(name="someEvent", type="flash.events.Event")] above your class definition is nice, but only if you use FlexBuilder. It gives you code hints and acts as strict-typing for MXML; in Flash, it's worthless.

For bigger applications, or for higher level events, if you can't bubble it up for a higher level view to handle, then just use a Singleton:

Model.instance.deeplyNestedMovieClipSays = "sup sup!";

Great advice Jesse! Thanks!

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)