tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/227-stage-resize-best-practice-for-initial-resizing-of-view-componentsRobotlegs: Discussion 2018-10-18T16:35:14Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T12:10:24Z2010-08-03T13:24:17ZStage resize: best practice for INITIAL resizing of view components<div><p>I would really like to hear your views on this.</p></div>Abel de Beertag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T13:14:28Z2010-08-02T13:14:28ZStage resize: best practice for INITIAL resizing of view components<div><p>The model approach wouldn't be too bad - although it's kind of a blend between a model and a service. Here's how I might approach it:</p>
<p>I wouldn't mediate the root application. Mediators can't be injected into other mediators (well, not easily anyway).</p>
<p>I'd create a StageService and inject the contextView into it: [Inject] public var contextView:DisplayObjectContainer;</p>
<p>I'd mark a public init() method in the Service with [PostConstruct] and set up the stage resize handler. At this point I'd also grab the current dimensions and store them on the Service. Personally, I wouldn't bother with a VO, a simple native Point object should suffice.</p>
<p>I'd inject the Service into any mediators that need the dimensions. They would be able to grab the dimensions from it during onRegister, and set up handlers to listen for changes.</p>
<p>Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T13:15:22Z2010-08-02T13:15:22ZStage resize: best practice for INITIAL resizing of view components<div><p>BTW, coupling a Mediator to a Service/Model is not really bad practice - Mediators <em>are</em> boundary objects.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T17:26:42Z2010-08-03T13:24:17ZStage resize: best practice for INITIAL resizing of view components<div><p>Thanks for your replies, Shaun!</p>
<p>I'll experiment with your service idea, I like it.</p>
<p>One question: when exactly is a method marked with the [PostConstruct] tag executed? I noticed that just mapping the class for injection doesn't do it.</p></div>Abel de Beertag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T17:28:48Z2010-08-03T13:24:17ZStage resize: best practice for INITIAL resizing of view components<div><p>Nevermind that. I found that the function is executed once the class is injected into another class. Thanks again!</p></div>Abel de Beertag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T17:35:06Z2010-08-02T17:35:06ZStage resize: best practice for INITIAL resizing of view components<div><p>That's not quite right. Methods marked with [PostConstruct] will be executed after all dependencies have been injected into <em>that</em> instance. As the properties won't be ready until <em>after</em> construction we need a way to know when dependencies have been injected.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T17:57:02Z2010-08-03T13:24:17ZStage resize: best practice for INITIAL resizing of view components<div><p>Ah, I see. Thanks for clearing that up.</p></div>Abel de Beertag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T18:19:17Z2010-08-02T18:19:17ZStage resize: best practice for INITIAL resizing of view components<div><p>Regarding the stage resize issue, can't you manually fire the signal the first time, after all the views are created?</p></div>Jonitag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T18:26:46Z2010-08-02T18:26:46ZStage resize: best practice for INITIAL resizing of view components<div><p>I think it's more about views that arrive <em>later</em> - after the signal has fired.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T18:31:40Z2010-08-02T18:31:40ZStage resize: best practice for INITIAL resizing of view components<div><p>Oh, I see.<br />
I don't know what this StageResizeVO carries, but if all you have is the stageWidth and stageHeight, then you can listen for Event.ADDED_TO_STAGE in your view and performe any aligning / sizing there.<br />
But this will populate alot of your views with the same event handler (onAddedToStage).</p></div>Jonitag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T18:37:04Z2010-08-02T18:37:04ZStage resize: best practice for INITIAL resizing of view components<div><p>Yeh, I think the idea is to find the most elegant solution to that problem.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-02T23:31:13Z2010-08-03T13:24:17ZStage resize: best practice for INITIAL resizing of view components<div><p>@Joni: Since I'm creating a fullscreen app, there are multiple variables that are important. It all comes from one major problem: when the user initializes the application, its browser dimensions will be different from the resolution I'm developing for. This means that I need to compare the initial browser dimensions to the original development dimensions, plus the current dimensions compared to the original dimensions to get the scaling values. :)</p></div>Abel de Beertag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-05T09:40:38Z2010-08-05T09:40:39ZStage resize: best practice for INITIAL resizing of view components<div><p>In HandBones I opted for the Model approach - works well for me. :)</p>
<p><a href="http://github.com/Matan/HandBones/blob/master/src/org/handbones/model/SizeModel.as">http://github.com/Matan/HandBones/blob/master/src/org/handbones/mod...</a></p></div>Matan Ubersteintag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-08-07T13:05:09Z2010-08-07T13:05:09ZStage resize: best practice for INITIAL resizing of view components<div><p>@Matan: Cool, thanks for the suggestion. :)</p>
<p>The Service approach feels the most logical to me and it works well.</p></div>Abel de Beertag:robotlegs.tenderapp.com,2009-10-18:Comment/23354292010-12-04T13:39:22Z2010-12-04T13:39:22ZStage resize: best practice for INITIAL resizing of view components<div><p>"I wouldn't mediate the root application. "</p>
<p>Im not sure why? I mediate my root application. and it works
fine :)</p></div>Nikos