Question

Is there a way to use getters and setters for Vectors?

Say, in my Main class, I would like to write

myVector.push(item);

and in another class, I have written:

public function get myVector():Vector.<int> {
     return _opponentCardList;
}

public function set myVector(myVector:Vector.<int>):void {
     _myVector = myVector;
}

This doesn't really work as you have to set _myVector to a Vector. But what if you just want to push(), pop() or splice?

Was it helpful?

Solution

Your getter and setter use different variables - is that intentional?

If the getter/setter myVector is in a different class, you need an instance of that class in your Main class before you can access it from there.

//in the Main class.
var obj:OtherClass = new OtherClass();
//the constructor of OtherClass should initialize _myVector
//otherwise you will get a null pointer error (1009) in the following line
obj.myVector.push(item);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top