質問

I have a setter for a vector that works properly, but I'm trying to make it do some additional things when one of the elements is changed.

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

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

If I do myVect[0] = 1, then _myVect becomes [1,0,0,0] but it doesn't even trace. How can I get the element number and assigned value from inside the setter?

役に立ちましたか?

解決

It doesn't trace because when using "myVector[0] = ", you're actually using the getter, not the setter (You GET the vector to then SET one of it s values).

I would only implement a getter.

Instead of myVect[0] = 1 you should do _myVect[0] = 1 or implement a public method like so:

public function updateVectorAt(value:int, index:int):void
{ 
    _myVect[index] = value; 
    // do the other stuff here...
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top