Creating a Weather Widget with XML and Actionscript 3.0


In this tutorial I’m presenting you a little weather widget, that could come handy for travel websites, or our personal page. If you make some changes on the code, you could show a different interface on your website, according to the weather on your city. Pretty cool stuff. We gonna connect weather.com XML data file with our flash widget. Weather.com offers us a free service to do that.

Requirements

Adobe Flash CS3

Try / Buy

Source Files

Download

Sign up to weather.com

The first thing we gonna do is login in our weather.com account:

https://registration.weather.com/ursa/profile

Or if we already don’t have an account we could register for free in here:

https://registration.weather.com/ursa/profile/new?

Registering for weather.com XML Data Feed

Once we are in our account, we gonna have a page like this one, where on the left we gonna have all the services we are subscribed and on the right, all the available services, the XML data feed is not there, it’s a little bit tricky.

So, we gonna signup to the XML data feed on this page https://registration.weather.com/ursa/xmloap/ Where we gonna tell to weather.com in which way we gonna use the data. If it’s for personal purpose, there’s no problem, but if it’s commercial purpose, you have to contact them, but everything is better explained on the mail you are going to receive.

So if our registration it’s ok, we gonna receive an email like this one (check on the spam inbox too, just in case).

The email explains us about the service, and there’s three important things to see in here:

  • Where to download the weather.com SDK (http://download.weather.com/web/xml/sdk.zip)
  • The weather.com XML Partner ID & License Key
  • How to make a properly formatted XML request for the service

Contents of the wheater.com SDK

On this package you gonna find a PDF, with the license agreement and some useful information about how to make a request for the services, and two folder, one with the weather.com logos, and the other with the weather icons we gonna use on this tutorial as reference. There’s 3 type of icon sizes, for this tutorial we gonna use the 93×93 icons. The icons are not too fancy, so we could download a free cool set of weather icons from here:

http://liquidweather.net/icons.php#iconsets

This iconsets and backgrounds are from the Liquid Weather++ appi.

Setting up our api key

We could put all our data inside flash, like the code of our city, our partner id, and so on, but it’s gonna be a pain in the ass every time we want to change it. So, it’s much better if we load this type of data externally form an XML file. The XML structure should looks like this:

	ARBA0009
XXXXXXXXX
	XXXXXXXXXX
	m

Loading our data in Flash

Now our hands on AS. We gonna do all the programming in just 2 frames, pretty easy. On the first frame, we load all the data to use it when we call the weather.com xml service. On the second frame, called “weather”, we load the weather.com xml and display the data. So, in our first frame:

  • We define the variables we gonna use
  • We call the xml that holds our data
  • Then we pass the data from the xml to our variables
  • And if everything it’s oki, we could go to the weather frame

stop();

//=================
//ini variables
//=================

//we define our variables to be loaded

var city:String;
var par_id:String;
var key:String;
var units:String;

//call the xml with our data

var data_xml_url:String = "data.xml";
var user_data:XML = new XML();
var data_url:URLRequest = new URLRequest(data_xml_url);
var dataLoader:URLLoader = new URLLoader(data_url);

dataLoader.addEventListener(Event.COMPLETE, dataLoaded);

function dataLoaded(e:Event):void
{
	user_data = XML(dataLoader.data);

	//pass the data from the XML to our variables

	city = user_data.city.toString();
	par_id  = user_data.parid.toString();
	key  = user_data.key.toString();
	units  = user_data.units.toString();

	//if everything it's oki, we could go to the weather frame

	gotoAndStop("weather");
}

The weather icons

To display the different type of weather, we need a movieClip that holds all the possible weathers, there’s not too much, just 47. So, we create a new movieclip and call it “icons_mc”, and inside the icons_mc we import all the icons from the Weather.com SDK icons folder, or from the cool icons from liquidweather. There’s a lil bit differences between the Weather.com SDK icons and the liquidweather icons. On the weather.com SDK, the icons 25 and 44 are N/A, if you gonna use the liquidweather icons, just replace the 25 and 44 icons with the N/A png. Don’t forget to put a stop(); in the first frame of the icons_mc, so the MC start stopped.

Loading the weather.com xml service

Now we could load the data from weather.com. We allow our swf to make calls from the domain “xoap.weather.com”, we make the icons_mc MovieClip invisible, because we don’t know which icon use yet, and we compose the weather xml url with the variables from the frame 1.

stop();
//=================
//allow domains
//=================
Security.allowDomain("*", "xoap.weather.com");
//=================
//ini settings
//=================
icons_mc.visible = false;
//=================
//XML
//=================
var weather_xml_url:String = "http://xoap.weather.com/weather/local/"+city+"?cc=*&link=xoap&par="+par_id+"&key="+key+"&unit="+units;

The xml from weather.com have this structure with some interesting data. As you can see there’s a lot of useful data to load, but we gonna load just the necessary by now. Later you could play with it and make an advanced one.

    en_US
MEDIUM
C km km/h mb mm Buenos Aires, Argentina 1:39 PM -34.61 -58.37 8:01 AM 5:52 PM -3 6/27/08 1:00 PM Local Time Buenos Aires Air Park, Argentina 13 13 Fog 20 1021.0 falling 11 N/A 360 N 82 2.5 2 Low 10 23 Waning Crescent

Displaying the data

To display the data, we have three different sprites:

  • The icons MovieClip
  • A dynamic text field to load the outside temp called “temp_txt”
  • A dynamic text filed in the bottom to make a lil speech about how feels to be outside called “info_txt”

Our main interest is on the XML file on the icon number, so we could show the right icon. We load the xml using our well formatted “weather_xml_url”, and traverse the xml three to find what we are looking for.

In this step we:

  • we load the temp on the temp_txt text field
  • make the icons visible, load the icon number and tell the icons:mc to stopn on thet icon frame
  • and finally we set the complementary text
var weather:XML = new XML();
var weather_url:URLRequest = new URLRequest(weather_xml_url);
var weatherLoader:URLLoader = new URLLoader(weather_url);

weatherLoader.addEventListener(Event.COMPLETE, weatherLoaded);

function weatherLoaded(e:Event):void
{
	weather = XML(weatherLoader.data);

	//we load the temp on the temp_txt text field
	temp_txt.text = weather.cc.tmp;

	//we make the icons visible, load the icon number and tell the icons:mc to stopn on thet icon frame
	icons_mc.visible = true;

	var weather_icon:int = Number(weather.cc.icon.toString())+1;
	icons_mc.gotoAndStop(weather_icon);

	//and finally we set the complementary text
	var ud:String = weather.head.ud;
	var us:String = weather.head.us;

	var city:String = weather.loc.dnam;
	var time:String = weather.loc.tm;
	var temp:String = weather.cc.tmp;
	var flik:String = weather.cc.flik;
	var term:String;

	if (temp == flik)
	{
		term = "and it feels like "+flik+" degrees,";
	} else {
		term = "but it feels like "+flik+" degrees,";
	}

	var wind_v:String = weather.cc.wind.s;
	var wind_gust:String = weather.cc.wind.gust;
	var wind_d:String = weather.cc.wind.d;
	var wind_t:String = weather.cc.wind.t;

	var hmid:String = weather.cc.hmid;
	var vis:String = weather.cc.vis;

	info_txt.text = "It's "+time+" here in "+city+". It's "+temp+" degrees out there "+term+" the wind blows from the "+wind_t+" at "+wind_v+" "+us+", the humidity is "+hmid+"% and the visibility is "+vis+" "+ud+".";
}

Now we could export our movie and if it’s cold outside, it’s good to be inside.

Final thoughts

We gonna need to know the international code of our city, so we could go to http://www.weather.com/common/welcomepage/world.html Search for our city, and find the code on our address bar. I know it’s a lil bit tricky but it works fine.

Hope you enjoyed this lil tutorial as much as I enjoyed writing for you.


Did you enjoy this article?
Share the love
Get free updates and win TTL prizes

Other Posts You Might Like

53 Responses to “Creating a Weather Widget with XML and Actionscript 3.0”

  1. jake says:

    Cool, nice tutorial
    Keep them coming

  2. John says:

    great tutorial! i have some questions though. are we only limited to the some of the xml data? i’d like to add the day and date information to the widget, so i’m trying to pull out the attributes “t” and “dt” in the day “0″ child element under dayf into a text box, but it’s not showing up. i’m probably doing it wrong as i’m very new to AS3.0 & XML. is there any way you could help me? thanks!

  3. Abel says:

    I get an ERROR:

    Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://www.worldkit.com/weather/weather.swf cannot load data from http://xoap.weather.com/weather/local/35216?cc=*&link=xoap&prod=xoap&par=1072119334&key=4d4b9329018d4592&unit=s.
    at weather_fla::MainTimeline/frame2()

  4. Fusionice says:

    Anyway to change the language or locale?

  5. @Fusionice: I’m not sure, but check the PDF on the SDK zip file, sure you could finde the call to change the lang and locale.

    @Abel: I’m at linux right now, so let me try to figure out why it’s the sandbox violation.

  6. canavrio roco says:

    John, ¿have you tried to replace the line:
    var time:String = weather.loc.tm;

    to this one:
    var time:String = weather.cc.lsup;
    ?

  7. Jon Hnefill says:

    I get the exact same sandbox violation error as Abel.

    Haven’t found a fix yet despite creating a crossdomain.xml file and placing it on the server.

    Have you manage to sort anything out ?

    /Johnny

  8. VIctor says:

    i have the same problem it will not connect to the weather page, i change the security permitions in the adobe page and it works but only wen you test it in you computer but when is in the server it dosent work, PLEASE HELP i need to find why.

    thanks

  9. Sudman says:

    Is anyone else having issues when publishing to a server the flash movie no longer gets the weather feed but on my local machine it works just find. Is there a fix for this? Thanks.

  10. Tim Tonsel says:

    John, I don’t know if you figured the multiple day forecast out but here is an example I made shows city, cc, days 1,2 and 3 temperature, Icon and day of the week.

    Hope it helps..

    Tim

    function weatherLoaded(e:Event):void
    {
    weather = XML(weatherLoader.data);
    temp_txt.text = weather.cc.tmp;
    day2_txt.text = weather.dayf.day[1].hi;
    day3_txt.text = weather.dayf.day[2].hi;
    day4_txt.text = weather.dayf.day[3].hi;
    text2_txt.text = weather.dayf.day[1].attribute(“t”);
    text3_txt.text = weather.dayf.day[2].attribute(“t”);
    text4_txt.text = weather.dayf.day[3].attribute(“t”);

    icons_mc.visible = true;

    var weather_icon:int = Number(weather.cc.icon.toString())+1;
    var weather2_icon:int = Number(weather.dayf.day[1].part[0].icon.toString())+1;
    var weather3_icon:int = Number(weather.dayf.day[2].part[0].icon.toString())+1;
    var weather4_icon:int = Number(weather.dayf.day[3].part[0].icon.toString())+1;
    icons_mc.gotoAndStop(weather_icon);
    day2_mc.gotoAndStop(weather2_icon);
    day3_mc.gotoAndStop(weather3_icon);
    day4_mc.gotoAndStop(weather4_icon);

    var city:String = weather.loc.dnam;
    var time:String = weather.loc.tm;
    var temp:String = weather.cc.tmp;
    var day2:String = weather.dayf.day[1].hi;
    var day3:String = weather.dayf.day[2].hi;
    var day4:String = weather.dayf.day[3].hi;
    var text2:String = weather.dayf.day[1].attribute(“t”);
    var text3:String = weather.dayf.day[2].attribute(“t”);
    var text4:String = weather.dayf.day[3].attribute(“t”);

    info_txt.text = city;
    day2_txt.text = day2;
    day3_txt.text = day3;
    day4_txt.text = day4;
    text2_txt.text = text2;
    text3_txt.text = text3;
    text4_txt.text = text4;
    }

  11. Anu says:

    I’m also having the same problem Abel, Jon Hnefill…… The thing works fine on desktop when the security settings are chnaged on the adobe page… but not on websitee!!! PLzzzz help!!!

  12. Ben Faubion says:

    Great Tutorial.. but i cant get this working either. I’m using this service to get the location code.. for example http://xoap.weather.com/search/search?where=Dallas

    works great in flash, but i just can get past the sandbox issue.. tried all the recommendations and I’m stuck at this point.. tried it with my key and partner id as well.

  13. pheugoo says:

    preview in flash does work
    but once it is published i loose all the fancy weather stuff!

  14. Tim, I’m trying to use multiple days forecast… but I don’t know how… I read the entire XML and I only get one day results… I have to load another XML Url? Thanks a lot!

  15. jhvh1134 says:

    To get this working from a web server, you can not do this by simply calling the xml file through a URLRequest. You need to use a proxy script that is placed locally on your webserver. I used proxy.php which looks like this:

    then, in flash assign the URLRequest to proxy.php instead of weather.com’s xml.

    Also, dont waste your time with policy file since weather.com has to allow you, which it doesnt unless youre one of ten sites.

  16. jhvh1134 says:

    you can google proxy.php

  17. n_n' says:

    Thanks a lot dear jhvh. I tried the proxy.php and it worked. I LOVE YOU. *KISSSS!*

  18. ASPIRINE says:

    jhvh1134 …please tell at which exact line and frame i have to make changes. plssss i don’t understand at all because i don’t see your code you’ve post on December 4th, 2008 at 8:22 pm

  19. Moroccom says:

    Hi all,

    The solution is easy for the sanbox security.

    You juszt have to add a .php file in your flash directory called
    secu_flash.php. It ll contains :

    Next, we go back into the flash in the second frame :

    and we put this little code.
    Replace the http://www.moroccom.com … by yours
    //=================
    //XML
    //=================

    var moroccom_xml_url:String = “http://www.moroccom.com/argazelabs/weather/v1/”;
    var xoap_xml_url:String = “http://xoap.weather.com/weather/local/”+city+”?cc=*&link=xoap&par=”+par_id+”&key=”+key+”&unit=”+units;

    var weather_xml_url:String = moroccom_xml_url+”secu_flash.php?maVariable=”+xoap_xml_url;
    //var weather_xml_url:String = “http://xoap.weather.com/weather/local/”+city+”?cc=*&link=xoap&par=”+par_id+”&key=”+key+”&unit=”+units;

    //trace(weather_xml_url);

    var weather:XML = new XML();
    var weather_url:URLRequest = new URLRequest(weather_xml_url);
    var weatherLoader:URLLoader = new URLLoader(weather_url);

    weatherLoader.addEventListener(Event.COMPLETE, weatherLoaded);

    I m sorry for my so bad english, french people ;)
    Hope i help.

    Happy new year

    F.

  20. Carlos Pinho says:

    @F.
    You need to create a var which converts miles to meters. Or, in the texfield which shows the miles, you convert it directly to meters. Simple math 1.8 km = 1 mile

  21. samantha alvarez says:

    Hi all, Moroccom, could you please paste the code for the secu_flash.php file, your last one didn´t appear, so, pleaseeeee!!! I´ve been struggling a lot for the last few weeks. Help!!!

    Moroccom Says:
    January 15th, 2009 at 6:49 pm

    Hi all,

    The solution is easy for the sanbox security.

    You juszt have to add a .php file in your flash directory called
    secu_flash.php. It ll contains :

    Next, we go back into the flash in the second frame :

    and we put this little code.
    Replace the http://www.moroccom.com … by yours
    //=================
    //XML
    //=================

    var moroccom_xml_url:String = “http://www.moroccom.com/argazelabs/weather/v1/”;
    var xoap_xml_url:String = “http://xoap.weather.com/weather/local/”+city+”?cc=*&link=xoap&par=”+par_id+”&key=”+key+”&unit=”+units;

    var weather_xml_url:String = moroccom_xml_url+”secu_flash.php?maVariable=”+xoap_xml_url;
    //var weather_xml_url:String = “http://xoap.weather.com/weather/local/”+city+”?cc=*&link=xoap&par=”+par_id+”&key=”+key+”&unit=”+units;

    //trace(weather_xml_url);

    var weather:XML = new XML();
    var weather_url:URLRequest = new URLRequest(weather_xml_url);
    var weatherLoader:URLLoader = new URLLoader(weather_url);

    weatherLoader.addEventListener(Event.COMPLETE, weatherLoaded);

    I m sorry for my so bad english, french people ;)
    Hope i help.

    Happy new year

    F.

  22. neo says:

    this is what U need Samantha

  23. rob says:

    Great tutorial, exactly what i needed. Thanks

  24. Jacek says:

    Do You know hot to change °F Fahrenheita to °C degrees??

    I’ve cheked sdk documantationa but I’haven’t found any answer.

  25. Carlos Pinho says:

    @Jacek

    As for the distance, you need to create a var that convert ºF to ºC.

    ºC=(ºF-32)/1,8 – This is the formula to convert ºF to ºC for more formulas check wikipedia.

    In this case, i think it should be something like:

    var temp:String = weather.cc.tmp;
    var celc:String = (temp-32)/1,8;

    Let me know if it worked.

  26. baris dogn says:

    its’not working

  27. Will says:

    for anyone like me who couldn’t get weather.com to work. (i tried like 4 different php methods, eh.. yea). you can easily use google weather and the same concept here.
    in fact i even went ahead and matched all the google icons to the ones in this tutorial, so thought i’d share that. if anyone’s interested in the php script (using curl) here it is http://www.abdulqabiz.com/blog/archives/2007/05/31/php-proxy-script-for-cross-domain-requests/Below are the things to change in order to use the icon set in this (excellent!) tutorial. You can fetch the other variables from xml easily. hope it helps someone out there, i spent way too much time fooling with weather.com. not worth it, trust me.

    var my_xml_url:String = “http://www.yoursite.com/”;
    var xoap_xml_url:String = “http://www.google.com/ig/api?weather=94107″;
    var weather_xml_url:String = my_xml_url+”load_xml.php?url=”+xoap_xml_url;
    var weather:XML = new XML();
    var weather_url:URLRequest = new URLRequest(weather_xml_url);
    var weatherLoader:URLLoader = new URLLoader(weather_url);
    weatherLoader.addEventListener(Event.COMPLETE, weatherLoaded);

    function weatherLoaded(e:Event):void
    {
    weather = XML(weatherLoader.data);
    trace(weather);

    var weather_num:int = new int();
    var weather_icon:String = weather.weather.current_conditions.icon.@data;

    if(weather_icon == “/ig/images/weather/chance_of_rain.gif”){weather_num = 12;}
    else if(weather_icon == “/ig/images/weather/sunny.gif”){weather_num = 33;}
    else if(weather_icon == “/ig/images/weather/mostly_sunny.gif”){weather_num = 35;}
    else if(weather_icon == “/ig/images/weather/partly_cloudy.gif”){weather_num = 31;}
    else if(weather_icon == “/ig/images/weather/mostly_cloudy.gif”){weather_num = 29;}
    else if(weather_icon == “/ig/images/weather/chance_of_storm.gif”){weather_num = 6;}
    else if(weather_icon == “/ig/images/weather/rain.gif”){weather_num = 13;}
    else if(weather_icon == “/ig/images/weather/chance_of_snow.gif”){weather_num = 9;}
    else if(weather_icon == “/ig/images/weather/cloudy.gif”){weather_num = 27;}
    else if(weather_icon == “/ig/images/weather/mist.gif”){weather_num = 3;}
    else if(weather_icon == “/ig/images/weather/storm.gif”){weather_num = 5;}
    else if(weather_icon == “/ig/images/weather/thunderstorm.gif”){weather_num = 1;}
    else if(weather_icon == “/ig/images/weather/chance_of_tstorm.gif”){weather_num = 38;}
    else if(weather_icon == “/ig/images/weather/sleet.gif”){weather_num = 6;}
    else if(weather_icon == “/ig/images/weather/snow.gif”){weather_num = 16;}
    else if(weather_icon == “/ig/images/weather/icy.gif”){weather_num = 8;}
    else if(weather_icon == “/ig/images/weather/dust.gif”){weather_num = 20;}
    else if(weather_icon == “/ig/images/weather/fog.gif”){weather_num = 21;}
    else if(weather_icon == “/ig/images/weather/haze.gif”){weather_num = 22;}
    else if(weather_icon == “/ig/images/weather/smoke.gif”){weather_num = 23;}
    else if(weather_icon == “/ig/images/weather/flurries.gif”){weather_num = 7;}
    else{weather_num = 0;
    var weaLoader2:Loader = new Loader();
    var weaReq2:URLRequest = new URLRequest(“http://www.google.com” +weather_icon);
    weaLoader2.contentLoaderInfo.addEventListener(Event.COMPLETE, showWea);
    weaLoader2.load(weaReq2);

    function showWea(event:Event):void
    {
    weaLoader2.x = 18;
    weaLoader2.y = 45;
    addChild(weaLoader2);
    }

    }
    //trace(weather_num);
    icons_mc.gotoAndStop(weather_num);
    icons_mc.visible = true;

    //add the rest of your parsed xml data to dynamic text fields in your mc here
    // ie temp_txt.text = weather.weather.current_conditions.temp_f.@data;

    }

  28. andres says:

    Me corre en flash!!!! y no en el servidor!!!!
    HELP!!!!

  29. andres says:

    help please not work on the server!!!!

  30. Display weather for any location in the world.
    Allow users to search and change locations, view current conditions, 5 day forecast for both night and day.
    Caches weather data locally. Weather data comes from the Weather.com XML feed.

  31. Bugoy says:

    it works fine when you preview it on flash(ctrl+ENTER) but when i tried to upload and open in Mozilla Firefox and IE i cant see the weather.swf inside the page…

    any ideas?

  32. WaWa says:

    i cant get this work on the server but work on my system
    can anyone share a work proxy.php ?
    thank you

  33. Happy says:

    Hi,
    Example works fine. when i try with flash but shows error when i tried to run it independent on locale system.
    Error:- Asking for flash player security it shows –
    SecurityError: Error #2028.
    How to avoid it to run independently to show weather.

    Please help…..

  34. wassim says:

    hello, can anyone help me use the same script to preview the next 4 days weather also ?? thanks !

  35. Elias says:

    Hi,
    great script, problem is if I load it inside an other flash movie the first icon in set flickers and shows no temp. When I preview the weather.fla on its own it works fine. It seems it’s not staying in place on the second frame and just jumps from 1 to 2 and back again… Any ideas?

  36. Elias says:

    As I’m testing this movie I see that there’s a problem when loading your AS3 coded weather swf inside an AS2 file, while if it’s loaded inside another AS3 it works fine.

    I have all files attached at the link below, any ideas?
    http://www.sendspace.com/file/tiflm7

  37. Mike says:

    hi, why would you put up this tutorial that obviously doesn’t work due to Security issues and not only NOT address the security issues is a WORKING manner but also NOT answer all your readers’ questions about the Security problem?

    Tutorial Fail.

  38. Alejo says:

    No tiene soporte este tutorial, no informa sobre la creación de proxy ni los problemas de seguridad ni crossdomain, asi que solo funciona localmente, en conclusión es un mal tutorial.

    No funciona!

  39. Adam Wolf says:

    Ok, this was a weird one. But based on a few leads in the comment section I was able to get this thing to ACTUALLY WORK.

    Create a file on your server next to where weather.swf is located called proxy.php and put the following code in it:

    0 ){
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }

    $response = curl_exec($ch);
    $response_headers = curl_getinfo($ch);

    if (curl_errno($ch)) {
    print curl_error($ch);
    } else {
    curl_close($ch);
    header( 'Content-type: ' . $response_headers['content-type']);
    print $response;

    }

    ?>

    Updating only the “Your URL here” Section with with the path to the rss feed containing your desired zipcode, partner ID and License key. It should look something like this.

    http://xoap.weather.com/weather/local/#####?cc=*&link=xoap&par=##########&key=################&unit=f

    (Note: once you update the #’s in that path with the above mentioned zip, partner ID and Lic. Ket you should be able to paste it in a browser and see the feed)

    Then proceed to the actionscripts panel in flash. In frame 1 either remove all of the code or simply comment it out, it’s un-necessary now.
    Frame 1 of weather.fla

    //stop();
    //=================
    //ini variables
    //=================

    //var city:String;
    //var par_id:String;
    //var key:String;
    //var units:String;

    //var data_xml_url:String = "data.xml";
    //var user_data:XML = new XML();
    //var data_url:URLRequest = new URLRequest(data_xml_url);
    //var dataLoader:URLLoader = new URLLoader(data_url);

    //dataLoader.addEventListener(Event.COMPLETE, dataLoaded);

    //function dataLoaded(e:Event):void
    //{
    //user_data = XML(dataLoader.data);

    //city = user_data.city.toString();
    //par_id = user_data.parid.toString();
    //key = user_data.key.toString();
    //units = user_data.units.toString();

    //gotoAndStop("weather");
    //}

    Now on to frame 2 of weather.fla
    Change this line of code

    var weather_xml_url:String = "http://xoap.weather.com/weather/local/"+city+"?cc=*&link=xoap&par="+par_id+"&key="+key+"&unit="+units;

    to this (making sure that it’s pointing to wherever you put your proxy.php)

    var weather_xml_url:String = "http://www.yourdomain.com/proxy.php";

    Upload proxy.php
    Upload weather.swf
    Enjoy.

  40. Adam Wolf says:

    Edit to last comment, it missed part of the proxy.php code when I posted.


    $post_data = $HTTP_RAW_POST_DATA;
    $header[] = "Content-type: text/xml";
    $header[] = "Content-length: ".strlen($post_data);

    $ch = curl_init('Your URL here');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    if ( strlen($post_data)>0 ){
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }

    $response = curl_exec($ch);
    $response_headers = curl_getinfo($ch);

    if (curl_errno($ch)) {
    print curl_error($ch);
    } else {
    curl_close($ch);
    header( 'Content-type: ' . $response_headers['content-type']);
    print $response;

    }

  41. Tim says:

    Hi Adam,
    i´ve testet your proxyScript and i always get the PHP-Error:
    Fatal error: Call to undefined function curl_init() in /myServer/proxy.php on line 6
    I have testet it on two different servers with PHP-Support
    Any idea?
    Regards Tim

    • Adam Wolf says:

      You have to have CURL enabled on the server for it to work. Guess I should have said that in my original post. Did you create a phpinfo file to see if curl was enabled?

      If not, create a .php file and name it whatever you want, usually phpinfo.php and put the following code in it and upload it to the server.

      opening php tag
      phpinfo();
      closing php tag

      visit http://www.yourwebaddress.com/phpinfo.php and see if curl support is enabled. If it is not, you will either have to have your hosting company enable it or enable it yourself. Googling that error should get you started on enabling curl.

      HTH
      -Adam

    • Adam Wolf says:

      Have you uploaded a phpinfo file to see if CURL is enabled on your server?

      -Adam

  42. Tim says:

    Ok-it`s working now.
    I just used:

  43. Casper .... says:

    I don’t get it working on a server PC (like http://www.mindlessgaming.com) and it’s for a school project so I used a little piece of that site, but can someone plz explane clearly how to let the as 3/XML code through the securrety.

    Thx, you guys are my last hope

    (sorry for bad english)

  44. Easy way to load XML is use PHP
    For exsample
    create new PHP file in the head type and it WORKS! simple !

    Good luck!

  45. jpavly says:

    It seems like Adam’s proxy.php gets me somewhere at last.

    Thanks

  46. Thanks for this awesome tutorial

  47. Pierre-Louis says:

    Hi,

    Thanks for the cool tutorial, but I did not have enough time to do this myself. If anyone is looking for a quick fix, I stumbled upon a free XML Weather Widget. It’s Flash and AS3 and I put it in my project in just a couple of minutes. It has tons of things I could change, including the images for the different weather patterns, and all of this via the XML file. I’m not the programmer/developer in the world and finding the Weather Widget saved me countless hours of head scratching and looking blankly at my screen. If anyone is interested you can find it here http://www.flashxml.net/weather-widget.html

    Good luck coding! P.L.

Leave a Reply

TTL VIP
Become a TTL VIP Member & Get Notified of The Best Changes in Technology, Plus Win Prizes in Our VIP Only Contests...

Tech News Tech Tutorials Smartphone News Tablet News Gaming News Free Software Infographics Contact