In ActionScript 3, I've read that the root variable references an instance of the Document Class.
Within my document class constructor, a trace(this == root) returns true. Later in the constructor, a constructor of another class is called. This constructor, however, states that root is null. Finally, tracing from an event listener gives me the result that root is [object Stage].
My goal is to have a single instance of a Document Class (in MainGame.as) and to be able to refer to that as (root as MainGame) throughout my ActionScript program. How can I do this?
If it matters, all of my code is in the default package.
Thanks!
The
rootpropety of aDisplayObjectbecomes a reference to the Document Class once theDisplayObjectis added to the display list. You can continue to userootbut be aware that only objects on the display list will work.You can read more about root here: