是否有要用于载体getter和setter的方法吗?

我说,在我的主类,我想编写

myVector.push(item);

和在另一个类中,我已经写:

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

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

这并没有真正的工作,你必须_myVector设置为一个向量。但是,如果你只是想推(),pop()方法或拼接什么?

有帮助吗?

解决方案

您getter和setter使用不同的变量 - ?是故意的。

如果在的getter / setter myVector是在不同的类,你需要一个类的实例在Main上课前,你可以从那里访问它。

//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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top