AS3:设置者和向量

时间:2013-10-02 14:25:55

标签: actionscript-3 vector setter

我有一个可以正常工作的矢量的setter,但是当其中一个元素被更改时,我正试图让它做一些额外的事情。

private var _myVect:Vector.<int> = new <int>[0,0,0,0];

public function set myVect(newVect:Vector.<int>):void {
    trace(newVect);
    _myVect = newVect;
}

如果我执行myVect [0] = 1,则_myVect变为[1,0,0,0],但它甚至没有跟踪。如何从setter中获取元素编号和赋值?

1 个答案:

答案 0 :(得分:0)

它没有跟踪,因为当使用“myVector [0] =”时,你实际上使用的是getter,而不是setter(你获取向量然后设置其中一个值)。

我只会实现一个吸气剂。

而不是myVect [0] = 1你应该做_myVect [0] = 1或实现像这样的公共方法:

public function updateVectorAt(value:int, index:int):void
{ 
    _myVect[index] = value; 
    // do the other stuff here...
}