Below is the code from my Flash Builder 4.5 project that gives an RSS-feed. The feed is showing correctly, but I'm having some problems with linking each news-article. So when you click in a article title, it should link to the according webpage. I have been able to extract the url for each article (3th column in the datagrid) and i also created a basic function that links to google when you click on the datagrid. What I need is that when you click on a row, you go to the according webpage. ANy help is welcome!
<?xml version="1.0" encoding="utf-8"?>
<s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="runningrssfeedstart(event)">
<fx:Declarations>
<s:HTTPService id="runningrssfeed"
url="{rss_request}"
result="runningrssfeed_resultHandler(event)"
fault="runningrssfeed_faultHandler(event)"/>
<s:ArrayCollection id="myAc"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
//imported classes
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.core.mx_internal;
import mx.events.FlexEvent;
import mx.formatters.DateBase;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.object_proxy;
[Bindable]
public var rss_request:String;
//parameters voor rss-feed + opdracht de httpservice te starten
public function runningrssfeedstart(event:FlexEvent):void
{
rss_request = 'http://www.coolrunning.com/engine/affiliate/rssLatest.rss';
runningrssfeed.send();
}
//Als rss werkt, neem dan info van volgende pad
protected function runningrssfeed_resultHandler(event:ResultEvent):void
{
myAc = event.result.rss.channel.item;
}
//Als rss functie mislukt, toon dan alert mat fault string
protected function runningrssfeed_faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultString);
}
//opent site van nieuwsbericht hoe google veranderen in juiste url?
public function openRss(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.google.com"), "_blank");
}
]]>
</fx:Script>
<mx:DataGrid click="openRss(event)" left="105" top="45" width="450" height="380" dataProvider="{myAc}" headerStyleName="headerBold">
<mx:columns>
<mx:DataGridColumn id="rssTitel" width="320" headerText="Artikel" dataField="title"/>
<mx:DataGridColumn headerText="Datum" dataField="pubDate"/>
<mx:DataGridColumn headerText="url" dataField="link"/>
</mx:columns>
</mx:DataGrid>
If you use the Spark DataGrid instead of the mx DataGrid (and I can think of no reason why you shouldn't) you can simply use its 'gridClick' event handler like this:
<s:DataGrid dataProvider="{dp}" gridClick="openRssAt(event.rowIndex)">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="title" />
<s:GridColumn dataField="pubDate" />
<s:GridColumn dataField="link" />
</s:ArrayList>
</s:columns>
</s:DataGrid>
public function openRssAt(index:int):void {
var url:String = dp.getItemAt(index).link;
navigateToURL(new URLRequest(url), "_blank");
}
However, if you wish to stick with mx DataGrid, you can use the itemClick
event handler in exactly the same way:
<mx:DataGrid dataProvider="{dp}" itemClick="openRssAt(event.rowIndex)">
<mx:columns>
<mx:DataGridColumn dataField="title"/>
<mx:DataGridColumn dataField="pubDate"/>
<mx:DataGridColumn dataField="link"/>
</mx:columns>
</mx:DataGrid>