views:

148

answers:

2

So, I'm building stuff in AS3, I have a main movie clip, and I have one set of navigation to be displayed twice (one is a normal side bar setup, the other is a fancy designer scrolly thing down the bottom). When one is clicked, the other should react to reflect what has happened.

Should main.menuA reference main.menuB, or should I set up EventDispatchers and EventListeners so the event routes through main? or when I initiate menuA and menuB, should I pass a reference of menuA to menuB and viceversa?

Honestly, in this case, it doesn't matter too much, but I need to stop bad practices from becoming bad habits.

+2  A: 

I'd recommend you go with event listeners and dispatchers. If your events bubble (and you set the scope for the listener to be on the "bubble path"), you don't need a direct reference from either button to the other.

Just make sure you clean up the events when you destroy the objects, or (and) use weak references.

Alex Jillard
+4  A: 

It makes most sense to setup events and change the corresponding control through main. If you did it the other way then each control would always have to be paired with the other, they shouldn't even be aware of each other.

But I have a slight change. You have a concept (PlayingStatus). This concept is independent of the way you draw it on the screen (obviously since you have two ways of doing it). Let's call them Layout1 and Layout2.

Both Layouts should hold a reference to the same PlayingStatus data. When one Layout modifies PlayingStatus, the PlayingStatus class can raise an event for each property (whatever those are) as it changes. Both Layouts would be listening for these events and redraw themselves when one arrives.

colithium
+1 For Model-View-Controller.
Sean Nyman
Model-View-Presenter (MVP) works better with Flash
TandemAdam