AS3获得玩家的宽度

时间:2012-12-29 10:26:37

标签: 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

1 个答案:

答案 0 :(得分:0)

您甚至在创建播放器对象之前尝试引用this

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

public class Player extends MovieClip {

   private var playerHalfWidth:int;

   public function Player() {

     playerHalfWidth = this.width/2;
   }