News Reader Component...
One of the things I love about Flex, is how easy it makes it to build components. I've built a simple news reader to add to FlexInABoxStock.
Before I post a whole lot more here I want to make sure that you realize that this application is starting off very simple and is going to grow in complexity and features. I'm going to be adding features and complexity to each of these components as well as developing others. By the end, this will be a full blown dashboard application.
Now, on to the jumping off point for the news reader component. The sample application can be viewed here.
The news reader displays the US markets the RSS feed from Yahoo! The actual feed is processed by ColdFusion and is returned as an array of structures from the CFC. It's then used as an ArrayCollection in Flex.
The application polls the server for the feed every minute, so any updates are processed automatically.
Adding ColdFusion at this point is an extra step, as Flex could do this without the aid of ColdFusion. However, I have other plans down the road for this component and incorporating ColdFusion now will make it easier.
Here's the CFC function used to parse the feed.
<cfargument name="feedURL" required="yes" type="string">
<cfset var rss = "">
<cfset var items = "">
<cfset var aNewsItems = ArrayNew(1)>
<cfhttp method="get" url="#arguments.feedURL#" />
<cfset rss = cfhttp.FileContent>
<cfset items = XMLSearch(rss, "/rss/channel/item")>
<cfloop from="1" to="#ArrayLen(items)#" index="i">
<cfset stItem = StructNew()>
<cfloop from="1" to="#ArrayLen(items[i].XMLChildren)#" index="j">
<cfset stItem[items[i].XMLChildren[j].XMLName] = items[i].XMLChildren[j].XMLText>
</cfloop>
<cfset arrayAppend(aNewsItems, stItem)>
</cfloop>
<cfreturn aNewsItems>
</cffunction>
Try it out and let me know what you think. If you've got any questions, just ask.


There are no comments for this entry.
[Add Comment]