2010-01-07 5 views
1

벡터에 게터와 세터를 사용할 수 있습니까?AS3 벡터 : getters 및 setters 사용?

말은, 내 메인 클래스에서, 나는

myVector.push(item); 

를 작성하고 다른 클래스에, 내가 쓴 싶습니다 : 설정 가지고

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

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

이 정말 작동하지 않습니다 벡터에 _myVector. 그러나 단지(), pop() 또는 splice를 원한다면 어떨까요?

답변

1

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); 
관련 문제