Actionscript 3 AS3获取播放器的宽度

Actionscript 3 AS3获取播放器的宽度,actionscript-3,class,object,actionscript,width,Actionscript 3,Class,Object,Actionscript,Width,这位于公共类中,用于查找播放器宽度的一半: public class Player extends MovieClip { private var playerHalfWidth:int = this.width/2; 我得到这个错误: 1119:Access of possibly undefined property width through a reference with static type class 甚至在创建Player对象之前,您就尝试引用此 将其

这位于公共类中,用于查找播放器宽度的一半:

   public class Player extends MovieClip
{    
   private var playerHalfWidth:int = this.width/2;
我得到这个错误:

1119:Access of possibly undefined property width through a 
reference with static type class

甚至在创建Player对象之前,您就尝试引用

将其移动到构造函数中是正确的方法:

public class Player extends MovieClip {

   private var playerHalfWidth:int;

   public function Player() {

     playerHalfWidth = this.width/2;
   }