質問

のベクトルのためのゲッターとセッターを使用する方法はありますか?

と言う、私のメインのクラスで、私が書きたいと思います。

myVector.push(item);

と別のクラスでは、私が書かれています:

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

public function set myVector(myVector:Vector.<int>):void {
     _myVector = myVector;
}
あなたはベクトルに_myVectorを設定するために持っているように、

これは実際に動作しません。しかし、あなたはちょうど、)(ポップ()を押すまたはスプライスしたい場合は何?

役に立ちましたか?

解決

あなたのゲッターとセッターは異なる変数を使用する - 意図的なことです。

? ゲッター/セッター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