all groups > flash actionscript > september 2005 >
You're in the

flash actionscript

group:

Weather Service


Weather Service knucklenutz
9/2/2005 8:48:52 PM
flash actionscript:
Hi all,

I know this topic has been posted before, but previous posts didn't seem to
lend any help. I am trying to retrieve weather conditions based on a specific
zip code. Many of the prior posts talked about web services. Do I need to be
running some sort of server side app to use a web service? I came across a
free PHP script using NuSOAP that was designed to do just what I was looking
for, but after punching in a zip, the weather was always -999, which is damn
cold :) I found the PHP scripts here:
http://www.flash-db.com/services/?clientID=7&sType=Weather

Does anyone have an useful info regarding a reliable weather service that may
or may not require Flash Remoting or some other server side app?

Thanks in advance!
Re: Weather Service NSurveyor
9/2/2005 10:05:08 PM
You could use yahoo to get an rss feed of the weather, and then find the
correct node and such. For example, go to http://weather.yahoo.com/ Then type
in your zip code into the " Find Weather - Enter city or zip code" box. Hit
search. When you reach the page for your weather, hit the orange RSS button.
This has all the info for the page you just were at. I used that information
and brought it into flash. Copy the url of the rss file. Put this code on frame
1 of a blank fla doc:

var url = 'http://xml.weather.yahoo.com/forecastrss?p=USNY1296&u=f';
var xml = new XML();
xml.ignoreWhite = true;
xml.onLoad = function(s){
trace(s ? 'Success' : 'Failure');
//
channelNode = this.firstChild.firstChild;
var locNode = channelNode.childNodes[6];
var tempNode = channelNode.childNodes[10].childNodes[5];
var unitNode = channelNode.childNodes[7];
//
var temp = tempNode.attributes.temp;
var units = unitNode.attributes.temperature;
var tempString = ''+temp+'?'+units;
//
var city = locNode.attributes.city;
var region = locNode.attributes.region;
//
trace('The temperature for '+city+', '+region+' is '+tempString);
}
xml.load(url);

Replace 'http://xml.weather.yahoo.com/forecastrss?p=USNY1296&u=f' with the url
you copied to the clipboard. (The one that's already there is for zip code,
12345, some place in NY, USA)

Re: Weather Service knucklenutz
9/2/2005 10:18:09 PM
Thanks for the reply,

Re: Weather Service NSurveyor
9/2/2005 10:19:30 PM
Re: Weather Service knucklenutz
9/2/2005 10:30:31 PM
I am trying to use the WebServiceConnector component to tap into a service that
accepts input zip codes and returns a result. I am getting mixed results
though. Debugging proves that the SWF is making a connection and retrieving a
result but it is incomplete. I am using the US weather service provided at:

http://www.webservicex.net/WeatherForecast.asmx?WSDL

And using the GetWeatherByZipCode operation.

ws.params["94111"];
ws.trigger();
function tempReceived(ev:Object) {
var temp:String = ev.target.results;
trace(temp);
}
ws.addEventListener("result", tempReceived);

Could there be some sort of cross domain policy file that is not allowing the
data to return?

Thanks
Re: Weather Service knucklenutz
9/6/2005 12:00:00 AM
Hi again. So I am now able to contact a weather web service and get data. The
only problem now is that the data is so nested in the result object I am not
sure how to extract it. I am using the following wsdl:

http://www.webservicex.net/WeatherForecast.asmx?WSDL

And the following code to contact the service:

import mx.services.*;
result_btn.onPress = function() {
var weatherservice = new
WebService("http://www.webservicex.net/WeatherForecast.asmx?WSDL");
weatherResultObj = weatherservice.GetWeatherByZipCode("94111");
weatherservice.onLoad = trace("loading");
weatherResultObj.onResult = function(result) {
trace(result);
};
};

It is easy to trace data in top of the data structure (ie Latitude, Longitude,
StateCode, etc) with the following:
trace(result.Latitude);

But I am getting lost in trying to retrieve some of the nested data like
MaxTempF and data stored in the Details array.

Any ideas?

Thanks so much!
Re: Weather Service NSurveyor
9/6/2005 12:00:00 AM
import mx.services.*;
result_btn.onPress = function() {
var weatherservice = new
WebService("http://www.webservicex.net/WeatherForecast.asmx?WSDL");
weatherResultObj = weatherservice.GetWeatherByZipCode("94111");
weatherservice.onLoad = function() {
trace("Loading...");
};
weatherResultObj.onResult = function(result) {
xml = new XML(this.response);
weather =
xml.firstChild.firstChild.firstChild.firstChild.childNodes[6].firstChild;
//Data
Day = weather.childNodes[0].firstChild.toString();
WeatherImage = weather.childNodes[1].firstChild.toString();
MaxTemperatureF = weather.childNodes[2].firstChild.toString();
MinTemperatureF = weather.childNodes[3].firstChild.toString();
MaxTemperatureC = weather.childNodes[4].firstChild.toString();
MinTemperatureC = weather.childNodes[5].firstChild.toString();
trace('Day: '+Day);
trace('Image: '+WeatherImage);
trace('Temp: hi '+MaxTemperatureF+'?F - low '+MinTemperatureF+'?F');
trace('Temp: hi '+MaxTemperatureC+'?C - low '+MinTemperatureC+'?C');
};
};

Re: Weather Service knucklenutz
9/6/2005 12:00:00 AM
Outstanding!

Many thanks. I have to say I was close but got lost in the firstchild calls in my xml.

Re: Weather Service NSurveyor
9/6/2005 12:00:00 AM
Re: Weather Service knucklenutz
9/7/2005 11:08:21 PM
Hi,

So I have encountered a new problem related to this posting. Any idea why
this code might work in one file and not another?

import mx.services.*;
var weatherservice = new
WebService("http://www.webservicex.net/WeatherForecast.asmx?WSDL");
trace(weatherservice);

One file returns an object, and one returns undefined. As far as I can tell
everything is the same with regards to Publish settings, etc. When I look in
the Configuration/Classes/mx/ directory, I don't even see a services/
directory. Yet the one file works.

Thanks!
Re: Weather Service knucklenutz
9/7/2005 11:28:42 PM
I have just figured out that you need WebServiceConnector instance in your document library before the code will work.

Sorry for the bother.

Re: Weather Service NSurveyor
9/8/2005 12:00:00 AM
AddThis Social Bookmark Button