Reputation: 1725
This has long bothered me.
When using stage resize, you could say something like this:
public class Preload extends MovieClip
{
protected var main:Main;
public function preloader()
{
this.main = new Main();
this.addChild(this.main);
stage.addEventListener(Event.RESIZE, this.onResize);
}
protected function onResize(e:Event): void
{
this.main.x = stage.stageWidth>>1;
this.main.y = stage.stageHeight>>1;
}
}
What about if Main needs to also resize? I have many systems which respond to a resize event and I do not know if I should simply add a stage Event.RESIZE listener to every screen or if this should be controlled from a single location.
For example, add this.main.resize() to the onResize listener above then implement an IResizable interface on my screens for example?
What is best practice?
EDIT: Or should resize be part of something more generic, like invalidate()
Upvotes: 0
Views: 6421
Reputation: 10837
For performance it's better to have only 1 Event.RESIZE
listener in your document class. Then propagate the event to all your sub classes and children with functions, or even better with the wonderful Signals framework by Robert Penner.
If you need to scale your document class the easiest way is to put all your content inside a Sprite
and scale that instead.
Upvotes: 1