在类之间的actionscript中使用VO



在我的类中,我构建了一个Weather VO(Visual Object),现在需要将它用于另一个类。我将如何使用它来修改第二类中文本字段的值?我尝试使用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;
    }

您的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;
}

相关内容

  • 没有找到相关文章

最新更新