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?
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!";
Posted by: JesterXL | November 28, 2007 05:24 AM
Great advice Jesse! Thanks!
Posted by: Jensa | November 28, 2007 09:37 AM