我有一个 Main 实例,我应该可以在任何地方访问它。如果我想访问级别上的变量,我应该能够:
_root.level.my_value
但是,当我在地图中调用 _root.level 时,.level 显示为 null。
Main.as(类文档)
package{
import flash.display.MovieClip;
public class Main extends MovieClip{
//Monostate
private static var _instance:Main;
public static function get instance():Main { return _instance; }
public var level:MovieClip;
public function Main(){
_instance = this; //Monostate
this.level = new Level();
}
}} //package / class
水平.as
package{
import flash.display.MovieClip;
public class Map extends MovieClip{
private var _root:MovieClip;
public function Map(){
_root = Main.instance
trace(_root);
trace(_root.level); //This should not be null
}
}} //package / class