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 so far

  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. MainEventMap.mxml lines 26 to 28 are commented out. When uncommented they do not compile because they use old Mate element names. Here is what the lines should say:

          `<EventAnnouncer generator="{WeatherEvent}" type="{WeatherEvent.GET}">
             <Properties location="94403" unit="f" />
  5. 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.

  6. 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.
  7. 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.
  8. 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
  9. I am Dredf send me info please today :),
  10. Send in my email answer about can in this web pages please!,
  11. i interesting about this health real blog,
  12. 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?

Leave a Reply

Leave this field empty