Welcome, Guest. Please login or register.
Did you miss your activation email?
08 Sep 2010, 03:52:04 UTC
Forum home
+  flexdeveloper.eu Forum
|-+  Flex and ActionScript 3.0
| |-+  ActionScript 3.0 (Moderators: JMWhittaker, Jan K, thewarpedcoder, James)
| | |-+  [Newbie help] Dynamically load multiple RSS Feeds into DataGrids
« previous next »
Pages: [1] Print
Author Topic: [Newbie help] Dynamically load multiple RSS Feeds into DataGrids (Read 101 times)
Quizje
Newbie FD
*
Posts: 2


« on: 26 Jul 2010, 15:10:24 UTC »

Hello everyone, this is my first post over here. I've been stumbling over the same problem for a couple of days now and I can't find a solution, no matter what I try. I think the main cause for this, is my lack of experience in Flex. So I am hoping someone here could give me some advice.

I am trying to do the following:
I have an XML file, containing the locations of RSS Feeds. I am trying to dynamically loop over this XMLfile to create an interface (using a viewstack for example), which shows a menu on the side, with the options of the RSSFeeds. By clicking one link, it should open that feed into the panel on the right.
After that, each linefeed should also be clickable and load the detailed RSS info, but I haven't even come to that yet.

I am stuck at a point where I am trying to connect the HTTPServices to the appropriate DataGrids. I've been trying a variety of different methods already, but each time I stumble upon one dilemma I can't solve.

My current attempt looks like this:

Main.mxml :
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="RSSFeedList.send()">

<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.collections.ArrayCollection;
import mx.controls.DataGrid;
import mx.rpc.events.ResultEvent;
import mx.controls.Button;
import mx.containers.Panel;
import mx.controls.Alert;
import mx.controls.LinkButton;
import script.RSSFeed;

[Bindable]
public var rssFeed:RSSFeed = new RSSFeed;

[Bindable]
public var iteratie:int = 0;

[Bindable]
public var xData:XMLList;


public function ShowCandy():void {
var txtFldX:LinkButton = new LinkButton();
txtFldX.label = "HOI";
CandyBar.addChild(txtFldX);
for each (var theItem:Object in RSSFeedList.lastResult.RSSFeeds.feed) {
//Debug
var txtFld:LinkButton = new LinkButton();
txtFld.label = String(iteratie);
CandyBar.addChild(txtFld);
iteratie++;

//Class fill
rssFeed.setAll(theItem.index, theItem.title, theItem.category, theItem.description, theItem.source);
//Panel makeup and placement
var cPanel:Panel = new Panel();
cPanel.id = "P" + iteratie;
cPanel.label = rssFeed.RSSName;
cPanel.title = rssFeed.RSSName;
CandyBar.addChild(cPanel);

//DataGrids makeup and placement
var dGrid:DataGrid = new DataGrid();
dGrid.id= "D" + iteratie;

var dColumns:Array = [];
var dColumn:DataGridColumn = new DataGridColumn("title");
dColumn.headerText = "Titel";
dColumns.push(dColumn);
dColumn = new DataGridColumn("pubDate");
dColumn.headerText = "Datum";
dColumns.push(dColumn);
dGrid.columns = dColumns;

cPanel.addChild(dGrid);

//Make HTTPService
var hService:HTTPService =  new HTTPService();
hService.url = rssFeed.RSSUrl;
hService.addEventListener(ResultEvent.RESULT, bindRSS);
hService.send();

dGrid.dataProvider = rssFeed.xData;

}
}

public function bindRSS(event:ResultEvent):void {
xData = event.result.RSSFeeds.feed as XMLList;
}

]]>
</mx:Script>



<mx:HTTPService id="RSSFeedList" url="xml/feeds.xml" showBusyCursor="true" result="ShowCandy()" />
<mx:HTTPService id="rssHTTP1" showBusyCursor="true"/>

<mx:VBox id="CandyBar" />

RSSFeed.as (Class)
Code:
package script
{
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;

public class RSSFeed
{

public var RSSName:String = "";
public var RSSCat:String = "";
public var RSSUrl:String = "";
public var RSSDescription:String = "";
public var RSSIndex:int = 0;

public var hService:HTTPService;

[Bindable]
public var xData:XMLList;

public function RSSFeed(){
}

public function httpFault(event:FaultEvent):void {
                var faultstring:String = event.fault.faultString;
                Alert.show(faultstring);

}

public function setAll( rssIndex:int, rssName:String, rssCat:String,rssDesc:String, rssURL:String ):void {
RSSName = rssName;
RSSCat = rssCat;
RSSUrl = rssURL;
RSSDescription = rssDesc;
RSSIndex = rssIndex;
}

public function makeService():void {

}

public function bindRSS(event:ResultEvent):void {
//xData = XML(event).RSSFeeds.feed;
}

//setters
public function setName(rssName:String):void{
RSSName = rssName;
}

public function setCat(rssCat:String):void {
RSSCat = rssCat;
}

public function setURL(rssURL:String):void {
RSSUrl = rssURL;
}

public function setDesc(rssDesc:String):void {
RSSDescription = rssDesc;
}

//Getters

public function getName():String {
return RSSName
}

public function getCat():String {
return RSSCat;
}

public function getURL():String {
return RSSUrl;
}

public function getDesc():String {
return RSSDescription;
}
}
}

The XML containing the feeds-info:

Code:
<?xml version="1.0" encoding="utf-8"?>
<RSSFeeds>
<feed>
<index>1</index>
<title>Fok Nieuws</title>
<category>Nieuws</category>
<description>Algemeen nieuws, gericht op jongeren</description>
<source>http://rss.fok.nl/feeds/nieuws</source>
</feed>

<feed>
<index>2</index>
<title>Tweakers.net</title>
<category>Technologie</category>
<description>De grootste informaticasite.</description>
<source>http://feeds.feedburner.com/tweakers/nieuws</source>
</feed>

<feed>
<index>3</index>
<title>Fox Sports</title>
<category>Sport</category>
<description>Algemeen Sportnieuws</description>
<source>http://msn.foxsports.com/feedout/syndicatedContent?categoryId=49</source>
</feed>

<feed>
<index>4</index>
<title>CNN Travel</title>
<category>Reizen</category>
<description>Al het reisgerelateerde nieuws.</description>
<source>http://rss.cnn.com/rss/cnn_travel.rss</source>
</feed>

</RSSFeeds>

The question is: How can I link the right HTTPService to the right DataGrid, so that each DataGrid will display the proper RSS Feed?

Thanks in advance for helping me! I've been stuck on this for days now.. I've done two complete video-tutorials about Flex, looked at dozens of examples on the internet, but none of them seems to work, or do the same that I am trying to do..




Logged
Quizje
Newbie FD
*
Posts: 2


« Reply #1 on: 27 Jul 2010, 05:03:22 UTC »

The problem above I managed to solve in a different way, using a custom component.

But I have a new problem: Currently I am loading 4 RSS Feeds, all of which are checked and the links are correct. But no matter what link I put in the first feed, it won't display.
The 2nd - 4th do, but the first never.. even if I change the order, the first one in the repeater doesn't show. What might cause this problem?

Logged
Pages: [1] Print
« previous next »
Share this on: Twitter Twitter Del.icio.us del.icio.us Digg Digg
Jump to:

©2006-2010 Flexdeveloper.eu/Jodie O'Rourke. All rights reserved.
Adobe®, Adobe® Flash™, Adobe® AIR™ and Adobe® Flex™ are registered trademarks of Adobe Systems Incorporated in the United States and other countries. All rights reserved.

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC