quieran ayudarme.
Estoy desarrollando un flash que toma el estado del tiempo
de Yahoo Weather... hasta aqui todo bien, lo pude hacer
funcionar con php.
El tema es que necesito que haya 2 pronosticos distintos
en el mismo swf...y no sé como hacerlo.
Este es el php que uso:
Código PHP:
<?php
$zip = SPXX0008;
define('WEATHER_URL', 'http://weather.yahooapis.com/forecastrss');
define('WEATHER_FILE', 'cache/weather');
class Weather {
var $data;
function getWeather($zip, $units='c') {
$units = strtoupper($units);
$path=WEATHER_URL."?p=$zip&u=c";
$this->data = @file_get_contents($path);
$fp = @fopen($file, 'w');
@fwrite($fp, $this->data);
@fclose($fd);
if(strlen($this->data) <= 0) return;
$attributes = explode('"', $this->GetTagAttributes('yweather:condition'));
$saved_units = explode('"', $this->GetTagAttributes('yweather:units'));
$location = explode('"', $this->GetTagAttributes('yweather:location'));
$forecastToday = explode('"', $this->GetTagAttributes('yweather:forecast',1));
$forecast = explode('"', $this->GetTagAttributes('yweather:forecast',1));
$saved_units = strtoupper($saved_units[1]);
$return = array();
$return['text'] = $attributes[1];
$return['temp'] = $this->convert($saved_units, $units, $attributes[5])."°{$units}";
$return['image'] = $this->TranslateCode($attributes[3]);
$return['city'] = $location[1];
$return['state'] = $location[3];
$return['country'] = $location[5];
$return['fDay'] = $forecast[1];
$dateObject = explode(" ", $forecast[3]);
switch($dateObject[1]){
case "Jan":
$date = "January ".$dateObject[0].", ".$dateObject[2];
break;
case "Feb":
$date = "February ".$dateObject[0].", ".$dateObject[2];
break;
case "Mar":
$date = "March ".$dateObject[0].", ".$dateObject[2];
break;
case "Apr":
$date = "April ".$dateObject[0].", ".$dateObject[2];
break;
case "May":
$date = "May ".$dateObject[0].", ".$dateObject[2];
break;
case "Jun":
$date = "June ".$dateObject[0].", ".$dateObject[2];
break;
case "Jul":
$date = "July ".$dateObject[0].", ".$dateObject[2];
break;
case "Aug":
$date = "August ".$dateObject[0].", ".$dateObject[2];
break;
case "Sep":
$date = "September ".$dateObject[0].", ".$dateObject[2];
break;
case "Oct":
$date = "October ".$dateObject[0].", ".$dateObject[2];
break;
case "Nov":
$date = "November ".$dateObject[0].", ".$dateObject[2];
break;
case "Dec":
$date = "December ".$dateObject[0].", ".$dateObject[2];
break;
}
$return['fDate'] = $date;
$return['fLow'] = $forecast[5];
$return['fHigh'] = $forecast[7];
$return['fCond'] = $forecast[9];
$return['fImage'] = $this->TranslateCode($forecast[11]);
return $return;
}
function GetTagAttributes($tag, $skip=0) {
$start = -1;
for($i = 0; $i <= $skip; $i++)
$start = strpos($this->data, "<{$tag}", $start + 1);
if($start === false) return false;
$start += strlen($tag) + 1;
$end = strpos($this->data, "</{$tag}>", $start);
if($end === false)
$end = strpos($this->data, '/', $start);
return trim(substr($this->data, $start, $end - $start));
}
function convert($in, $out, $temp) {
if($in == $out) return $temp;
return number_format(($temp - 32) / 1.8, 0);
}
function TranslateCode($code) {
$time = date('G', time());
$night = ($time <= 5 || $time >= 20); // night is between 8 pm and 6 am
switch($code) {
case 39: return "ThunderStorm";
case 2: return "WindyRain";
case 43: return "Snow";
case 18: return "Sleet";
case 7: return "IcyFrozenSnow";
case 8: return "IcyDrizzle";
case 9: return "Drizzle";
case 35: return "IcyRain";
case 40: return "Showers";
case 13: return "LightSnow";
case 14: return "MedSnow";
case 15: return "WindySnow";
case 19: return "Dust";
case 20: return "Fog";
case 21: return "Haze";
case 22: return "Smoke";
case 24: return "Wind";
case 26: return "Clouds";
case 27: return "MostlyCloudyNight";
case 28: return "MostlyCloudyDay";
case 29: return "PartlyCloudyNight";
case 30: return "PartlyCloudyDay";
case 31: return "Moon";
case 32: return "Sun";
case 33: return "FairNight";
case 34: return "FairDay";
case 36: return "Hot";
case 44:
if($night) return "PartlyCloudyNight";
else return "PartlyCloudyDay";
case 45:
case 47:
if($night) return "NightThunderStorm";
else return "SunnyThunderStorm";
case 46:
if($night) return "NightSnow";
else return "Snow";
default: return "Unknown";
}
}
}
$weather = new Weather();
$weather = $weather->getWeather($zip, 'c');
echo "&city=$weather[city]&state=$weather[state]&country=$weather[country]&temp=$weather[temp]&pic=$weather[image]&condtext=$weather[text]&fDay=$weather[fDay]&fDate=$weather[fDate]&fLow=$weather[fLow]&fHigh=$weather[fHigh]&fCond=$weather[fCond]&fImage=$weather[fImage]";
?>
http://www.mediafire.com/?sharekey=b...4e75f6e8ebb871
El flash tiene 1 campo llamado _root.temp y un mc llamado comp que son
los graficos del sol y la lluvia, que ilustran el clima.
Y luego un mc on la siguiente acción:
Código:
_level0.condtext = "not_loaded"; loadVariablesNum("weather.php", 0);
y en otro frame
Código:
if (_level1.condtext == "not_loaded") { gotoAndPlay(2); } else { _root.condm._visible = true; _root.condm.gotoAndStop(_level1.picm); _root.locm = _level1.city + ", " + _level1.state + ", " + _level1.countrym; _root.tempm = _level1.tempm+"° C "; _root.cond_title = _level1.condtext; play(); }
Si me ayudan, estaré muy agradecido.
Saludos.