A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Streaming Weather

  1. #1
    Junior Member
    Join Date
    Aug 2005
    Posts
    1

    Streaming Weather

    Does anybody know how to stream weather into your flash movie from an outside source? Any help would be appreciated

  2. #2
    A Happy Guy
    Join Date
    Jul 2005
    Posts
    107
    ummm....
    Be a little more specific.
    Aristotle was famous for knowing everything. He tought that the brain exists merely to cool the blood and is not involved in the process of thinking.

  3. #3
    Perverse Futurist villain2's Avatar
    Join Date
    Sep 2002
    Location
    Baltimore, MD
    Posts
    891
    Go to the weather channel's RSS feeds. They'll require you to set up a free account with them.

    You can then include the rss into your flash movie.

    You'll need to make a php proxy file which will duplicate the RSS feed on your server (flash cannot call the rss page itself from weather.com). Then, write actionscript to call the proxy.php page. Your user can enter a zipcode variable, or you can designate that variable on your own.

    Proxy should look something like:
    <?php
    $zipcode = $_REQUEST['zipcode'];
    $handle = fopen ("proxy_load.php", "w");
    fputs($handle, "<?php");
    fputs($handle, "\r\n");
    fputs($handle, "\r\n");
    fputs($handle, "\$dataURL = \"http://xoap.weather.com/weather/local/" . $zipcode . "?cc=*&dayf=5&prod=xoap&par=yourpar&key=yourkeyfro mweatherchannel\";");
    fputs($handle, "\r\n");
    fputs($handle, "\r\n");
    fputs($handle, "readfile(\$dataURL)");
    fputs($handle, "\r\n");
    fputs($handle, "\r\n");
    fputs($handle, "?>");

    fclose($handle);
    echo "success=1";

    ?>
    That will write the proxy_load.php file that the Flash movie can read. From there, you simply use actionscript to designate the text fields or input component (whichever you choose) to display the values.

    This requires knowledge of parsing xml in actionscript. That is a long and involved process which I'm not going to detail here, but there are plenty of tutorials and books on how to do so.

    An example would be:
    //Create the XML Object
    myXML = new XML()
    myXML.ignoreWhite = true
    //Load XML file
    myXML.load("Weather/proxy_load.php")
    //Make a reference to current timeline
    myXML.ref = this
    // Parse XML and fetch
    myXML.onLoad = function(success){
    if(success){
    var root = myXML.firstChild;
    nodes = root.childNodes;
    for(var i=0; i<nodes.length; i++) {
    subnodes = nodes[i].childNodes
    windsubnodes = subnodes[7].childNodes
    fdsubnodes = subnodes[2].childNodes
    fdiconnodes = fdsubnodes[4].childNodes
    sdsubnodes = subnodes[3].childNodes
    sdiconnodes = sdsubnodes[4].childNodes
    thdsubnodes = subnodes[4].childNodes
    thdiconnodes = thdsubnodes[4].childNodes
    fthdsubnodes = subnodes[5].childNodes
    fthdiconnodes = fthdsubnodes[4].childNodes
    orsubnodes = subnodes[1].childNodes
    oriconnodes = orsubnodes[5].childNodes
    nwindnodes = oriconnodes[2].childNodes

    this.ref["Area"+i].text = nodes[1].attributes.id
    this.ref["Humidity_txt"+i].text = subnodes[8].firstChild.toString()+" %"
    ... and so on. Lines like "Humidity_txt"+i mean the blank text field you insert into your flash movie should have an instance name of: Humidity_txt1 and so on.

    I'd suggest also using shared objects to allow your users to save their settings, but it's not required.

    Like I said, it is a long process, but quite rewarding to finish. It took me about three days to figure it all out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center