AS3 벡터 : 게터와 세터 사용?
-
19-09-2019 - |
문제
벡터에 게터와 세터를 사용하는 방법이 있습니까?
내 메인 클래스에서는 글을 쓰고 싶습니다
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);
제휴하지 않습니다 StackOverflow