在 ActionScript 3 中,我有 read root
变量引用文档类的一个实例。
在我的文档类构造函数中,一个 trace(this == root)
返回 true
.稍后在构造函数中,调用另一个类的构造函数。然而,这个构造函数声明 root
是 null
.最后,从事件监听器跟踪给我的结果是 root
是 [object Stage]
.
我的目标是拥有一个文档类的单个实例(在 MainGame.as
中)并且能够将其称为 (root as MainGame)
在我的 ActionScript 程序中。我怎样才能做到这一点?
如果重要的话,我的所有代码都在默认包中。
谢谢!
最佳答案
root
DisplayObject
的属性一旦DisplayObject
成为对文档类的引用被添加到显示列表中。您可以继续使用root
但请注意,只有显示列表中的对象才能工作。
You can read more about root here :
The root property of the Stage object is the Stage object itself. The root property is set to null for any display object that has not been added to the display list, unless it has been added to a display object container that is off the display list but that is a child of the top-most display object in a loaded SWF file.
关于actionscript-3 - `root` 不同地方的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14591981/