Feed on
Posts
Comments

Flex Blog Reader

I’m learning Flex and picked up one thing working through the tutorial I couldn’t get from Mr. Google anywhere.

The basic tutorials are at the macromedia livedocs site. Under “Getting Started with Flex 2,” “Lessons,” there are a couple of tutorials that introduce the DataGrid control. The basic tutorial application retrieves data from an RSS feed and displays it. I extended this a bit to deal with multiple blog sites. I have it hosted so you can see what it looks like, and the code with modifications is available, too. You’ll need the Flash 9 plugin to play with it, so Solaris users are out of luck for the time being.

Dynamic Data Grid

At any rate, the main thing I had trouble with was using the selectedIndex property on the DataGrid control to select the first returned article after retrieving the RSS feed. The trick is to set the index though the updateComplete event on the DataGrid control. My inclination was to attempt to set the property immediately after the feedRequest.send(). This can’t work since the send() is asynchronous and causes the DataGrid to be updated sometime after the send() method call. Attempting to set the selectedIndex property immediately after the send() is futile since the DataGrid won’t have been updated yet.

This is a perfect example of why you need to know how the message processing loops work in modern GUI frameworks. I have no idea what this looks like in Flex, but I’ll be finding out after this. This bit may be obvious to experienced Flex developers, but it wasn’t obvious to me at first, and I wasn’t able to find any help on this anywhere.

Proxy HTTPService Connections

Flex requires a crossdomain.xml on the servers where you want to retrieve RSS. This is a security requriement somewhat akin to Java applet security model that does not allow an applet to connect to a server other than the domain the applet is hosted on. You can get around this with a proxy, but the example PHP code for setting up your server to proxy the RSS feeds is a bit inflexible.

I’ve included a modified example in the zip file that will allow you to set the url you want to proxy as a parameter to the PHP script. The second two blogs in the example code show how to use this.

For example, the URL for Jeff Savit’s blog is

http://blogs.sun.com/jsavit/feed/entries/rss

This is retireved by the Flex component through this URL

http://blog.louspringer.com/BlogReader/bin/proxy.php?url=http://blogs.sun.com/jsavit/feed/entries/rss

I’ll leave these things up as long as I can, but suspect that the proxy code might be abused. I’ll watch my traffic for a while and see. I guess I can tighten it up if I need to. In the real world this should be coded to proxy a hard-coded list of URL’s.

Technorati , , ,

One Response to “Flex Blog Reader”

  1. on 28 Jan 2007 at 12:50 pm david

    Hi,

    Welcome to Flex. You mention the basic tutorials on the LiveDocs site. Just FYI, you should also check out: http://www.adobe.com/devnet/flex/ The quickstarts and the cookbook should be helpful, as well as some of the feature articles.

    Anyway, welcome to Flex…

    David Adobe

Trackback URI | Comments RSS

Leave a Reply