0

在我的課程中,我構建了一個Weather VO(Visual Object),現在需要將它用於另一個類。 我將如何使用它來修改我的第二課中文本字段的值?我試圖使用getters和setter來無濟於事。在類之間的動作腳本中使用VO

第一頁:

vo=new WeatherVO();//Visual Object for the weather data 
    vo.city = _xmlData.channel.ns1::[email protected]+", "+_xmlData.channel.ns1::[email protected];//city, st 
    vo.currentTemp = _xmlData.channel.item.ns1::[email protected]; 
    vo.currentCondition = _xmlData.channel.item.ns1::[email protected]; 
    vo.currentCode = _xmlData.channel.item.ns1::[email protected]; 
    vo.sunrise = _xmlData.channel.ns1::[email protected]; 
    vo.sunset = _xmlData.channel.ns1::[email protected]; 

第二頁:

public function set vo(value:WeatherVO):void 
    { 
     _weather=value; 
    } 

    public function get vo():WeatherVO 
    { 
     return _weather; 
    } 

回答

0

你的getter和setter方法應該是WeatherVO類的方法有助於將修改並在屬性檢索該類。使用您提供的有限代碼示例,我的建議是將天氣數據像這樣通過WeatherVO構造函數傳遞。

public function WeatherVO(_city:String, _currentTemp:String, _currentCondition:String, _currentCode:String, _sunrisde:String, _sunset:String) { 
    city = _city; 
    currentTemp = _currentTemp; 
    currentCondition = _currentCondition; 
    currentCode = _currentCode; 
    sunrise = _sunrise; 
    sunset = _sunset; 
} 

//Here is an example getter and setter for the city value. 
public function get City() { 
    return city; 
} 

public function set City(_city:String) { 
    city = _city; 
}