Mapping a resize event

d4rklit3's Avatar


05 Feb, 2011 01:15 AM

I would like all my views to respond to a resize event. I have been able to do something like:

contextView.stage.addEventListener(Event.RESIZE, onResize);

and then pass that on to the dimensions to the view:

view.resize(width, height);

Similarly I managed to do it in the startupCommand the same way except then mapping Event.RESIZE to the commandMap
and having the ResizeCommand class throw a resize event that the entire project can listen for.

I feel like the latter is a better way but I am not sure if that is still the optimal solution. Does anyone have a good solution for this?

  1. 1 Posted by Abel de Beer on 05 Feb, 2011 12:55 PM

    Abel de Beer's Avatar

    If I had to choose from these 2 options, I would go for the first one, because in that case you don't need an extra Command and Event class.

    The 'problem' is that a lot of the times you'll need to do extra calculations to scale and position your view components. For example, you need to take into account the initial stage sizes compared to the sizes you used for development. In that case in can be useful to have a StageService / StageManager class that does these calculations for you, and then have your mediators listen for events / signals from that class. The mediator can then request the corresponding values for that specific view. I chose this approach for my own project and it works very well.

    Also, there's some more discussion on this topic on this forum already:

  2. Stray closed this discussion on 18 Feb, 2011 07:15 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac