I wonder what benefits gives making stage non-static reference in each object instead of making it global. Because of that I have only problems with dereferencing null. But, there must be case why Adobe crew made it that way. So, can someone explain me that behaviour? And what problems can I have when I use something like the following code, and use gStage everywhere I need stage?
package
{
public var gStage: Stage;
public class Main extends Sprite;
{
public function Main()
{
if (stage)
init();
else
stage.addEventListener (Event.ADDED_TO_STAGE, init);
}
public static function init(): void
{
stage.removeEventListener (Event.ADDED_TO_STAGE, init);
gStage = stage;
}
}
}
By the way, why in every AS3 code sample I've ever seen Main extends Sprite?
Although each Flash movie usually has a single stage on which visible display objects are drawn, there is not just a single "global" stage in AIR applications; each window has its own stage, and hence each window object has to have its own instance reference to its own stage. It wouldn't be right to make a single static global stage object in that case — what if an AIR application requires multiple windows?