topical media & game development
professional-flex-code-21-com-wiley-proflex2-chapter21-commands-GetWeatherCommand.ax
professional-flex-code-21-com-wiley-proflex2-chapter21-commands-GetWeatherCommand.ax
(swf
)
[ flash
]
package com.wiley.proflex2.chapter21.commands
{
import com.adobe.cairngorm.commands.ICommand;
import mx.rpc.IResponder;
import com.adobe.cairngorm.control.CairngormEvent;
import com.wiley.proflex2.chapter21.business.WeatherDelegate;
import com.wiley.proflex2.chapter21.events.GetWeatherEvent;
import mx.utils.ObjectUtil;
import mx.controls.Alert;
import com.wiley.proflex2.chapter21.model.ModelLocator;
import com.wiley.proflex2.chapter21.vo.WeatherVO;
public class professional-flex-code-21-com-wiley-proflex2-chapter21-commands-GetWeatherCommand implements ICommand, IResponder
{
public function execute( event : CairngormEvent ) : void
{
var delegate : WeatherDelegate = new WeatherDelegate( this );
var initialEvent : GetWeatherEvent = GetWeatherEvent( event );
delegate.getWeather(initialEvent.locationId, initialEvent.unit);
}
//-------------------------------------------------------------------------
public function result( event : Object ) : void
{
//trace(ObjectUtil.toString(event.result.rss.channel));
if (event.result)
{
var item:Object = event.result.rss.channel;
var weather:WeatherVO = new WeatherVO();
weather.location = item.title;
weather.sunrise = item.astronomy.sunrise;
weather.sunset = item.astronomy.sunset;
weather.link = item.link;
weather.conditions = item.item.condition.text;
weather.date = item.item.condition.date;
weather.code = item.item.condition.code;
weather.temp = item.item.condition.temp;
weather.humidity = item.atmosphere.humidity;
weather.visibility = item.atmosphere.visibility;
weather.windspeed = item.wind.speed;
weather.units.distance = item.units.distance;
weather.units.pressure = item.units.pressure;
weather.units.speed = item.units.speed;
weather.units.temperature = item.units.temperature;
weather.highTemp = item.item.forecast[0].high;
weather.lowTemp = item.item.forecast[0].low;
model.weather = weather;
model.showWeatherDetail = true;
}
}
//-------------------------------------------------------------------------
public function fault( event : Object ) : void
{
Alert.show(event.fault);
}
[Bindable]
public var model:ModelLocator = ModelLocator.getInstance();
}
}
(C) A. Eliëns
2/9/2007
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.