package com.beabloo.widgets.weather { import com.beabloo.entities.LoadListener; import com.beabloo.entities.WeatherConditionsLoader; import flash.display.MovieClip; import flash.display.Loader; import flash.net.URLRequest; import flash.text.TextField; import flash.text.TextFormat; public class GenericWeatherWidget implements LoadListener { var city_mc:MovieClip; var currentTemperature_mc:MovieClip; var currentWeatherIcon_mc:MovieClip; var tomorrowLowTemperature_mc:MovieClip; var tomorrowHighTemperature_mc:MovieClip; var tomorrowWeatherIcon_mc:MovieClip; var tfFormat:TextFormat; var iconsSet:String = "/images/weatherImages"; var conditionsLoader:WeatherConditionsLoader; public function GenericWeatherWidget(city_mc:MovieClip, currentTemperature_mc:MovieClip, currentWeatherIcon_mc: MovieClip, tomorrowLowTemperature_mc:MovieClip, tomorrowHighTemperature_mc:MovieClip, tomorrowWeatherIcon_mc:MovieClip, tfFormat:TextFormat) { // constructor code this.city_mc = city_mc; this.currentTemperature_mc = currentTemperature_mc; this.currentWeatherIcon_mc = currentWeatherIcon_mc; this.tomorrowLowTemperature_mc = tomorrowLowTemperature_mc; this.tomorrowHighTemperature_mc = tomorrowHighTemperature_mc; this.tomorrowWeatherIcon_mc = tomorrowWeatherIcon_mc; this.tfFormat = tfFormat; } public function load() { conditionsLoader = new WeatherConditionsLoader(this); conditionsLoader.loadWidget(null); } public function setIconsSet(iconsSet:String) { this.iconsSet = iconsSet; } public function loadSuccessful(weatherConditions:Object, loader:Object) { var tempLoader:Loader; var iconLoader:Loader; trace("Country: " + weatherConditions.country); trace("City: " + weatherConditions.city); trace("currentTemperature: " + weatherConditions.currentTemperature); trace("tomorrowLowTemperature: " + weatherConditions.tomorrowLowTemperature); trace("tomorrowHighTemperature: " + weatherConditions.tomorrowHighTemperature); trace("currentWeatherName: " + weatherConditions.currentWeatherName); trace("tomorrowWeatherName: " + weatherConditions.tomorrowWeatherName); trace("woeid: " + weatherConditions.woeid); if (currentWeatherIcon_mc != null) { iconLoader = new Loader(); iconLoader.load(new URLRequest("http://localdevice.beabloo.com" + iconsSet + "/en/" + weatherConditions.currentWeatherName)); //iconLoader.load(new URLRequest("http://localdevice.beabloo.com/images/weatherImages/en/sunny.swf")); currentWeatherIcon_mc.addChild(iconLoader); currentWeatherIcon_mc.width = 70; currentWeatherIcon_mc.height = 70; iconLoader.x = 0; iconLoader.y = 0; currentWeatherIcon_mc.scaleX < currentWeatherIcon_mc.scaleY ? currentWeatherIcon_mc.scaleY = currentWeatherIcon_mc.scaleX:currentWeatherIcon_mc.scaleX = currentWeatherIcon_mc.scaleY; } if (this.tomorrowWeatherIcon_mc != null) { iconLoader = new Loader(); iconLoader.load(new URLRequest("http://localdevice.beabloo.com" + this.iconsSet + "/en/" + weatherConditions.currentWeatherName)); //iconLoader.load(new URLRequest("http://localdevice.beabloo.com/images/weatherImages/en/sunny.swf")); tomorrowWeatherIcon_mc.addChild(iconLoader); tomorrowWeatherIcon_mc.width = 70; tomorrowWeatherIcon_mc.height = 70; iconLoader.x = 0; iconLoader.y = 0; tomorrowWeatherIcon_mc.scaleX < tomorrowWeatherIcon_mc.scaleY ? tomorrowWeatherIcon_mc.scaleY = tomorrowWeatherIcon_mc.scaleX:tomorrowWeatherIcon_mc.scaleX = tomorrowWeatherIcon_mc.scaleY; } if (city_mc != null) { if (city_mc.cityNameBox != null) { trace("city_mc.cityNameBox.text: " + city_mc.cityNameBox.text); city_mc.cityNameBox.text = weatherConditions.city; } } if (currentTemperature_mc != null) { var currentTemperatureTF: TextField = new TextField(); currentTemperatureTF.defaultTextFormat = tfFormat; currentTemperatureTF.htmlText = "" + weatherConditions.currentTemperature + "º"; currentTemperature_mc.addChild(currentTemperatureTF); } if (this.tomorrowLowTemperature_mc != null) { var tomorrowLowTemperatureTF: TextField = new TextField(); tomorrowLowTemperatureTF.defaultTextFormat = tfFormat; tomorrowLowTemperatureTF.htmlText = "" + weatherConditions.tomorrowLowTemperature + "º"; tomorrowLowTemperature_mc.addChild(tomorrowLowTemperatureTF); } if (this.tomorrowHighTemperature_mc != null) { var tomorrowHighTemperatureTF: TextField = new TextField(); tomorrowHighTemperatureTF.defaultTextFormat = tfFormat; tomorrowHighTemperatureTF.htmlText = "" + weatherConditions.tomorrowHighTemperature + "º"; tomorrowHighTemperature_mc.addChild(tomorrowHighTemperatureTF); } } public function loadError(objectId:String, loader:Object) { } } }