Something useful that I wanted to blog about since my last AS3 project, but slipped my mind. Trevor McCauley (a.k.a. Senocular), had written a very useful article about the workaround to access stage and root properties for non-display object classes or display objects that are yet added to the stage.
I had that exact issue that was highlighted in his article, and until I read it, I had to pass an explicit reference to the classes just to gain access to either the stage or root properties. It was of most inconvenience to throw around references like that and made my code very ugly (which doesn’t make me happy at all
).
His solution was simple yet enlightening. With the instantiation of a top level class in the document class to store these references as public static variables, my problems were solved! *w00t!*
Do check out the article and source code for this issue.
























Yeah, this problem also used to plague me for quite some time. The answer was so simple as you mentioned, declare like so:
var StageObj:Stage = stage;
In the main class, and any subsequent functions, which extend the stage movieclip, you can even just refer to it without requiring a variable declaration, like so:
stage.width;
stage.height;
etc’s.
Edward