Actionscript 3.0 Setter - Getter

时间:2009-07-24 16:00:33

标签: actionscript-3 class setter getter

我想将我的Main Class中的Constructor值传递给另一个Class。

主类:

public function Main() {

        Snap.locationX = 350;
    }

另一类:

   public function get locationX():Number{
      return _value;
   }


   public function set locationX(x:Number):void{
      _value = x;   
   }

返回1061: Call to a possibly undefined method locationX through a reference with static type Class.

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您在上面定义的setter和getter方法是INSTANCE方法。看起来你在Snap类本身上调用Snap.locationX而不是Snap类的实例。

尝试(在Main()下):

var snapObj:Snap = new Snap();
snapObj.locationX = ...