PDA

Volledige versie bekijken : Rss


TitiVb
%Europe/Berlin %632 %2006, 15:10
Hoi,
ik probeer een rss reader te maken waarvoor ik een rss doorgeef en dan weergeef in een list.
Maar dit lukt mij (nog) niet. Iemand Suggesties?
Dit is de code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" themeColor="haloOrange">

<mx:HTTPService url="{getRss()}" id="myHTTPData" useProxy="false"/>

<mx:Script>
<![CDATA[
import mx.controls.*;
import mx.rpc.http.HTTPService;

var myURL:String="http://www.zattevrienden.be/taxonomy/term/81/0/feed";

private function rssinput(input):void
{
setRss(input);
Alert.show(getRss());
reinitializeRss(input);
}

private function getRss():String
{
return myURL;
}

private function setRss(input):void
{
myURL = input;
}

private function reinitializeRss(input):void
{
myHTTPData.cancel();
myHTTPData.send();
}
]]>
</mx:Script>

<mx:Panel x="162" y="10" width="700" height="517" layout="absolute" title="RSS Reader">
<mx:Label x="10" y="10" text="{myHTTPData.lastResult.rss.channel.title}" fontFamily="Verdana" fontSize="18" color="#004080"/>
<mx:DataGrid x="372" y="46" id="dgPosts" width="298" dataProvider="{myHTTPData.lastResult.rss.channel.item}" height="288" color="#004080" fontFamily="Verdana" fontSize="13" fontWeight="bold">
<mx:columns>
<mx:DataGridColumn headerText="Posts" dataField="title" />
</mx:columns>
</mx:DataGrid>
<mx:TextArea width="354" htmlText="{dgPosts.selectedItem.description}" height="288" color="#004080" fontSize="13" fontFamily="Verdana" fontWeight="bold" x="10" y="46" editable="false"/>
<mx:LinkButton label="Volledige post lezen" click="navigateToURL(new URLRequest(dgPosts.selectedItem.link));" color="#004080" fontSize="16" fontFamily="Verdana" textAlign="left" x="10" y="342"/>
<mx:Button x="10" y="445" label="Verzenden" click="rssinput(input.text)"/>
<mx:TextInput x="10" y="415" id="input" width="354"/>
<mx:Button x="560" y="10" label="Standaard RSS" click="reinitializeRss()"/>
<mx:Label x="10" y="383" text="Nieuwe Rss initializeren" fontSize="16" color="#0080c0" fontWeight="bold"/>
</mx:Panel>

</mx:Application>

TheDutch
%Europe/Berlin %848 %2006, 20:21
Wat lukt er niet? Wat duidelijker wezen hoor ;).

titter
%Europe/Berlin %595 %2006, 14:18
Wel als ik een rss-link intyp in input en dan op de button eronder druk zou de httpservice moeten veranderen en de nieuwe posts moeten weergeven. Maar dit lukt niet en zou niet weten wat ik verkeerd doe.

TheDutch
%Europe/Berlin %867 %2006, 20:49
Ik heb een flink aantal dingen aangepast dus bekijk het goed om te zien wat er nu zoal gebeurd in de code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" themeColor="haloOrange">

<mx:HTTPService showBusyCursor="true" url="{currentRSSFeedURL}" id="myHTTPData" useProxy="false"/>

<mx:Script>
<![CDATA[
import mx.controls.*;
import mx.rpc.http.HTTPService;

[Bindable]
private var currentRSSFeedURL:String;
private var standardRSSFeedURL:String = "http://www.zattevrienden.be/taxonomy/term/81/0/feed";

private function rssinput(input:String):void
{
setRss(input);
reinitializeRss();
}

private function getRss():String
{
return currentRSSFeedURL;
}

private function setRss(input:String):void
{
currentRSSFeedURL = input;
}

private function reinitializeRss():void
{
myHTTPData.cancel();
myHTTPData.send();
}

private function resetRSSFeed():void{
currentRSSFeedURL = standardRSSFeedURL;
reinitializeRss();
}
]]>
</mx:Script>

<mx:Panel x="162" y="10" width="700" height="517" layout="absolute" title="RSS Reader">
<mx:Label x="10" y="10" text="{myHTTPData.lastResult.rss.channel.title}" fontFamily="Verdana" fontSize="18" color="#004080"/>

<mx:DataGrid x="372" y="46" id="dgPosts" width="298" dataProvider="{myHTTPData.lastResult.rss.channel.item}" height="288" color="#004080" fontFamily="Verdana" fontSize="13" fontWeight="bold">
<mx:columns>
<mx:DataGridColumn headerText="Posts" dataField="title" />
</mx:columns>
</mx:DataGrid>

<mx:TextArea width="354" htmlText="{dgPosts.selectedItem.description}" height="288" color="#004080" fontSize="13" fontFamily="Verdana" fontWeight="bold" x="10" y="46" editable="false"/>

<mx:LinkButton label="Volledige post lezen" click="navigateToURL(new URLRequest(dgPosts.selectedItem.link));" color="#004080" fontSize="16" fontFamily="Verdana" textAlign="left" x="10" y="342"/>

<mx:Button x="10" y="445" label="Verzenden" click="rssinput(input.text)"/>

<mx:TextInput x="10" y="415" id="input" width="354"/>

<mx:Button x="560" y="10" label="Standaard RSS" click="resetRSSFeed"/>

<mx:Label x="10" y="383" text="Nieuwe Rss initializeren" fontSize="16" color="#0080c0" fontWeight="bold"/>
</mx:Panel>

</mx:Application>

Elke variable, return value, en argument moet altijd een een data type hebben. Dat is niet noodzakelijk maar wel zoals het hoort. Daarnaast is het sneller, duidelijker, en het kan veel problemen helpen voorkomen.

Kijk ook eens naar dit LiveDocs artikel over Bindables (http://livedocs.macromedia.com/flex/2/docs/00001653.html). Dat is één van de krachtigste features uit Flex 2. Je kunt een variable bindable maken en op het moment dat die variable wijzigt zal dit doorgevoerd worden op alle plekken waar die variable gebruikt wordt.

Er zijn een paar goede boeken over Flex 2 van Adobe zelf:

PDF (gratis): http://www.adobe.com/support/documentation/en/flex/
Boekenset (€72,60): https://store2.adobe.com/cfusion/store/html/index.cfm?event=displayProduct&categoryOID=1579079&store=OLS-NL

titter
%Europe/Berlin %539 %2006, 12:56
Bedankt voor de applicatie en voor de informatie.
Nu kan ik me weer een tijdje bezig houden ;)