PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: hesten on July 06, 2009, 04:21:06



Title: Stage resizing
Post by: hesten on July 06, 2009, 04:21:06
Hi

I am building an application that needs to run "fullscreen" (as in fullscreen within the browser, not a "take over"). When the window is resized the different elements obviously needs to reposition.

For this I use at StageMediator, whose viewComponents is stage. The StageMediator listens for the RESIZE event and sends a ApplicationFacade.STAGE_RESIZED notification.

Every other mediator that controls a view component that needs to reposition naturally listens for this notification.

Heres my concern, should the repositioning logic be in the view component or in the mediator? It seems that if I put it in the component it breaks some of the reuseability as you cannot assume that a component needs these things?
If I put it in the meditors the begin to more than merely mediate, which seems to break best practice?

Does it make sense?

Regards


Title: Re: Stage resizing
Post by: Jason MacDonald on July 06, 2009, 06:07:47
Resizing is definetly a function of the view component. There shouldn't be any "logic" in your mediators. I'd also recommend having a view component listen for stage events itself, rather than dispatching an event through PMVC. All components on the display list have access to the stage to add event listeners to.


Title: Re: Stage resizing
Post by: hesten on July 06, 2009, 06:51:13
Yeah that makes sense. And you're absolutely right that components themselves should register for stage events instead of sending notifications.

(on a side note, do you know if a loaded swf file would contain 2 stage objects one for each swf (the loading file and the loaded file).

Thanks a lot, that just simplified things a bit :)


Title: Re: Stage resizing
Post by: Jason MacDonald on July 06, 2009, 08:22:27
There is only ever one stage in a flash application, regardless of how many modules/SWF's are loaded. THey all point to the same "root" stage.

Just have your components/modules listen for the ADD_TO_STAGE event and then have them register with the stage for the resize event. This ensures you have access to the stage before trying to add an event listener to it (otherwise it'll throw an error if you do it before the stage is available). It's also a good idea to listen for when components are removed from the stage and have them remove their own stage event listeners for good clean-up.


Title: Re: Stage resizing
Post by: hesten on July 06, 2009, 11:54:11
Thank you very much Jason