以下是我的Flash Builder 4.5项目中提供RSS-feed的代码。 Feed正确显示,但我在链接每篇新闻文章时遇到一些问题。因此,当您单击文章标题时,它应链接到相应的网页。我已经能够为每篇文章(数据网格中的第3列)提取网址,并且我还创建了一个基本功能,当您单击数据网格时链接到谷歌。我需要的是当你点击一行时,你会转到相应的网页。欢迎任何帮助!
<?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>
答案 0 :(得分:2)
如果您使用Spark DataGrid而不是mx DataGrid(我可以认为没有理由不这样做),您可以简单地使用它的'gridClick'事件处理程序:< / p>
<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");
}
但是,如果您希望坚持使用mx DataGrid,则可以完全相同的方式使用itemClick
事件处理程序:
<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>