为什么我的Actionscript 3类中的stage未定义,即使我已经导入了Stage类?

mlt*_*ltt 3 stage actionscript-3

 package    {

 import flash.display.Stage;

 public class MyGlobal {

  public static  var CX:Number = stage.stageWidth / 2;
  public static  var CY:Number = stage.stageHeight / 2;  

 }

}
Run Code Online (Sandbox Code Playgroud)

错误是"1120: Access of undefined property stage."为什么?

Joe*_*oks 9

如前所述,stage是从DisplayObject继承的类的属性.在将类添加到舞台之前,舞台不可用于舞台,通常是通过DisplayObjectContainer的addChild方法.