0

在我的班级中,我构建了一个 Weather VO(视觉对象),现在需要将它用于另一个班级。我将如何使用它来修改第二堂课中文本字段的值?我尝试使用 getter 和 setter 无济于事。

第一页:

vo=new WeatherVO();//Visual Object for the weather data
    vo.city = _xmlData.channel.ns1::location.@city+", "+_xmlData.channel.ns1::location.@region;//city, st
    vo.currentTemp = _xmlData.channel.item.ns1::condition.@temp;
    vo.currentCondition = _xmlData.channel.item.ns1::condition.@text;
    vo.currentCode = _xmlData.channel.item.ns1::condition.@code;
    vo.sunrise = _xmlData.channel.ns1::astronomy.@sunrise;
    vo.sunset = _xmlData.channel.ns1::astronomy.@sunset;

第二页:

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

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

1 回答 1

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;
}
于 2013-08-17T18:17:16.327 回答