yahoo AS 3.0 weather API with flash

Here’s a pretty simple AS 3.0 example of using the yahoo weather API in flash. Nothing too fancy going on here. I plan to use it for something just a little more interesting than this, but I wanted to share this simple version because there aren’t a lot of non-flex samples out there.

You can see the sample here.

Start out by creating an instance of the WeatherService class:

//establish the weather service class
var ws:WeatherService = new WeatherService;
var w:Weather = new Weather;

Then, use the getWeather method to receive the weather information you’re looking for.

//grab the weather restults when the button is pressed
function getMyWeather(event:MouseEvent):void {
//use the zip code entered to get the weather
loc = zip_txt.text;
ws.getWeather(loc, "ENGLISH_UNITS");
}

getWeather takes just two parameters: your location and the type of units you’d like returned. My sample file is using US zip codes, but there are other location options available.
The full list of APIs available and documentation are here.

And here’s the FLA source for the flash sample.

Have a comment or question? Find me on twitter or email me.