| Getting Started with Flex 2 > Lessons > Retrieve and Display Data > Create a dynamic link | |||
The RSS feed doesn't provide the full text of the posts, but you still want users to be able to read the posts if they're interested. While the RSS feed doesn't provide the information, it does provide the URLs to individual posts. In the item node of the XML feed, this information is contained in a field called link.
You decide to create a dynamic link that opens a browser and displays the full content of the post selected in the DataGrid.
lick property in the <mx:LinkButton> tag so that the application source looks like the following:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="feedRequest.send()" layout="absolute">
<mx:HTTPService
id="feedRequest"
url="http://weblogs.macromedia.com/mchotin/index.xml"
useProxy="false" />
<mx:Panel x="10" y="10" width="475" height="400" title="{feedRequest.lastResult.rss.channel.title}">
<mx:DataGrid id="dgPosts" x="20" y="20" width="400" dataProvider="{feedRequest.lastResult.rss.channel.item}">
<mx:columns>
<mx:DataGridColumn headerText="Posts" dataField="title"/>
<mx:DataGridColumn headerText="Date" dataField="pubDate" width="150" />
</mx:columns>
</mx:DataGrid>
<mx:LinkButton x="20" y="225" label="Read Full Post" click="navigateToURL(new URLRequest(dgPosts.selectedItem.link));"/>
<mx:TextArea x="20" y="175" width="400"/>
</mx:Panel>
</mx:Application>
The value of the link field of the selected item in the DataGrid control, dgPosts.selectedItem.link, is specified in the argument to the navigateToURL() method, which is called when the user clicks the LinkButton control. The navigateToURL() method loads a document from the specified URL in a new browser window.
|
NOTE |
|
The navigateToURL() method takes a URLRequest object as an argument, which in turn takes a URL string as an argument. |
A browser opens and runs the application. Click an item in the DataGrid control and then click the Read Full Post link. A new browser window should open and display the blog page with the full post.
In this lesson, you used an RPC service component called HTTPService to retrieve data from an RSS feed, and then you bound the data to a Label, DataGrid, TextArea, and LinkButton control. To learn more, see the following topics in Flex 2 Developer's Guide:
Flex 2.01