下面是我的 Flash Builder 4.5 项目中提供 RSS 提要的代码。提要显示正确,但我在链接每篇新闻文章时遇到了一些问题。因此,当您单击文章标题时,它应该链接到相应的网页。我已经能够提取每篇文章的 url(数据网格中的第 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>