Weather Widget

An example that uses the Yahoo! Weather API to retrieve weather information. The location and unit to use are sent via flash vars (added to the html). When running your project, you need to add this flash var to your html template: location=your_location (replace your_location).

While this example is simple, it shows two important features:

  1. how to use the PropertyInjector and
  2. how to extend Mate by adding a tag that handles results and fault returned by the weather service. We have an in-depth tutorial about this example and topic.

View Source

Download Source

<br /><div id="inlineExample"> <script type="text/javascript"> // <![CDATA[ var so = new SWFObject('/assets/content/examples/weatherWidget/WeatherWidget.swf', 'website', '190', '200', '9', '#2E4061'); so.useExpressInstall('/assets/scripts/swfobject/expressinstall.swf'); so.addVariable("location", "92651"); so.addParam('menu', 'false'); so.write('inlineExample'); // ]]> </script> </div>

12 responses

  1. Great Framework!!! You also did a great job presenting at WebManiacs this week.

    I'm curious to know..., do you have any suggestions on how to use this sample widget / example without using FlashVars? I guess I'm looking for a code example on how to change the weather data based on an zip code selected in a Flex 3 list box.
  2. Hi Bill,
    Doing that should be pretty simple, since the main code is implemented in the WeatherEvent.GET EventHandlers. It would be a matter of dispatching the WeatherEvent.GET event with the location you get from your list. Something like this in your view:

    var event:WeatherEvent = new WeatherEvent(WeatherEvent.GET, true);
    event.location = myList.selectedItem (or something like this)

    (You might also need to set the unit property in the event, which I think is either f or c)
  3. This is great... would be even cooler if you could display a forcast...
  4. Just curious as to the design decision here to define a few Model objects that encapsulate a few properties vs just having those properties defined as individual injected variables like in the Stock Quote example.

  5. Ryan,
    The reason for that was to make the view as simple as possible, and have any formatting of data done in a different place.
  6. in Initializer I don't see where unit is defined in the AC_FL_RunContent in the index.template.html. I see location but no unit.
  7. ceaseoleo,
    unit is not there because it uses the default. If you want to change it, simply add it after the location with &unit=YOUR_UNIT
  8. Hi there.....nice widget. I have setup the files but I keep getting a name space error. It says that cannot resolve component (*) within MainEventMap?
  9. In this what should I have to pass as a location on flashvars??
    A city name ? or any code for the city?
    Because when I pass let's say "Ahmedabad"
    It shows nothing..
    but instead if I pass
    it shows correct result...

    so how can I get the code related to city / location ?
    Or am I missing something ?
  10. has someone got my point / issue ?
    or should I elaborate more ?
  11. sid,
    What you need to pass is what Yahoo!'s API will accept as is. For US, zip codes work, but for other countries you may need to pass the specific code. You'd need to check Yahoo's page to see how to get the code.
  12. Laura thanxs 4 ur concern.

    Well there is one more query that why do we need extensions ?
    Means are there only to handle the events processes executed by IActionList in our own way?

    And if so then y do we need to extend the MATE ?
    Can't we do something else ?

    Otherwise plz explain the Extensions basic usage in brief.

Comments now closed