PDA

View Full Version : Broadcast global component change


petkusj@virtualight.com
01-16-2008, 09:54 PM
As I've mentioned in my other thread, I'm creating a bunch of components that extend a base component.

I'd like for that base component to be able to tell all instances of the sub-classed components when a global change is coming. For instance, I want the user to be able to increase the type size used in all buttons, lists and text fields, just like a browser has a text increase/decrease command.

I have accomplished this, but I'd like to know if I've taken the best approach.

What I've done is set the base class to dispatch an event targeted to the stage, and my sub-classes components have a stage level addEventListener.

stage.dispatchEvent(new LCARSEvents(LCARSEvents.GLOBAL_CHANGE, false, false));

and

stage.addEventListener(LCARSEvents.GLOBAL_CHANGE,g lobalChange);

Of course, to make this work, I had to instantiate my base class and add it to the display list -- addChild(baseClassInstance) -- or else the base class has no idea what a stage is.

In the past, what I've done is keep an array of each object as it gets instantiated and whenever a global update is needed, I just for ... each through the array, calling the update function for each instance.

I'd appreciate any thoughts as to which is the more efficient path.

Thanks,

Jennifer

PS I hope I didn't double post this. I think my last go round I hit Preview instead of Submit.