【问题标题】:Using a VO in actionscript between classes在类之间的动作脚本中使用 VO
【发布时间】:2013-08-17 13:48:57
【问题描述】:

在我的班级中,我构建了一个 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;
    }

【问题讨论】:

    标签: actionscript-3 flash-builder getter-setter value-objects


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 2013-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-27
      相关资源
      最近更新 更多