Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 1,003
Registered: ‎01-16-2011
My Device: PlayBook (sim)
My Carrier: Rogers

Adding RSS functionality

Hey there,

 

I'm trying to add a simple RSS function to my app that will be displayed in the following way:

bar across the top with the different sites, list of articles displayed in a list on the left, and the article on the right.

 

Now, because this is just an add on to my app it doesn't need to be very complicated - no need to add feed or delete feeds, possibly just save feeds for offline use (maybe).

 

Either way, I've been playing around with the RSS sample code and don't see anywhere in it where I would specify the url to load to pull in the articles. I also have been unable to launch the sample code on either the device or the desktop air application, so I'm having a difficult time seeing what the code will look like to the end user.

 

If anyone has any suggestions or sites to check out that would be great. I've posted my code below, but considering how much of a mashup it is I doubt it will be of any use.

//array to list which sites to load
newsArr = new Array(); newsArr.push({label:"site 1"}); newsArr.push({label:"site 2"}); newsArr.push({label:"site 3"}); newsArr.push({label:""}); newsArr.push({label:""}); newsArr.push({label:""}); newsArr.push({label:""}); newsArr.push({label:""}); newsBar = new TileList(); newsBar.setPosition(0,110); newsBar.setSize(1024,40); newsBar.columnCount = 8; newsBar.columnWidth = 128; newsBar.rowCount = 1; newsBar.rowHeight = 40; newsBar.cellPadding = 0; newsBar.selectionMode = ListSelectionMode.SINGLE; newsBar.scrollable = false; newsBar.dataProvider = new DataProvider(newsArr); newsBar.addEventListener(ListEvent.ITEM_CLICKED, getFeedTitles); newsBar.setSkin(NewsCellRenderer); newsBar.selectedIndex = 0; addChild(newsBar); private function getFeedTitles(e:ListEvent):void{ this.activityIndicator = new ActivityIndicator(); activityIndicator.x = 150; activityIndicator.y = 335; activityIndicator.width = 35; activityIndicator.height = 35; activityIndicator.animate(true); addChild(this.activityIndicator); var url:String = e.data.data; var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest(url); request.method = URLRequestMethod.GET; //setting all of the error handling for the web request loader.addEventListener(Event.COMPLETE, onDataLoad); loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError); loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError); loader.load(request); } private function onIOError(event:IOErrorEvent):void { //need to implement what to do on error condition var alert:AlertDialog = new AlertDialog(); alert.title = "Loader Error (" + event.errorID + ")"; alert.message = "Error: " + event.text; alert.modalAlpha = 0.1; alert.dialogSize = DialogSize.SIZE_SMALL; alert.addButton("Ok"); alert.show(); removeChild(this.activityIndicator); } private function onSecurityError(e:SecurityErrorEvent):void { } //displays the list of all of the rss items when they come back private function onDataLoad(e:Event):void{ removeChild(this.activityIndicator); var rssList:List = new List(); rssList.x = 0; rssList.y = 110; rssList.height = 490; rssList.width = 300; var rawRSS:String = URLLoader(e.target).data; var dp:DataProvider = new DataProvider(); var rssXML:XML = new XML(URLLoader(e.target).data); //loop through all of the items and create the object containing the label (title) and the data(link to the article) for(var item:String in rssXML.channel.item){ dp.addItem({label:rssXML.channel.item[item].title, data:rssXML.channel.item[item].link}); } rssList.dataProvider = dp; //setting the event for each of the items being clicked, this will load up in the web view in the getFeed event rssList.addEventListener(ListEvent.ITEM_CLICKED, getArticle); addChild(rssList); } private function getArticle(e:ListEvent):void{ this.activityIndicator = new ActivityIndicator(); activityIndicator.x = 662; activityIndicator.y = 335; activityIndicator.width = 35; activityIndicator.height = 35; activityIndicator.animate(true); addChild(this.activityIndicator); var url:String = e.data.data; if(webView != null){ webView.dispose(); } var webView = new QNXStageWebView(); webView.enableCookies = true; webView.enableJavascript = true; webView.enableScrolling = true; webView.addEventListener(Event.COMPLETE, loadWebView); webView.loadURL(url); } private function loadWebView(event:Event):void{ this.activityIndicator.visible = false; var rect:Rectangle = new Rectangle(595, 50, 425, 500); webView.viewPort = rect; webView.autoFit = true; webView.stage = stage; }

 

 

 

- If you like my response/post, or it helped you find an answer you were looking for, please provide a Kudo - white star to the bottom right of this post. -
- Please use the search bar at the top, or check out the PlayBook FAQ's for help getting started -
- Hockey DrillBook -
Developer
Posts: 1,269
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Adding RSS functionality

[ Edited ]

If you are talking about the FullRSSReader example, take a closer look at how they add items to the shared object, in the saveNewFeed() function.  It looks like you are only creating feed name labels but no URL's.  Set breakpoints in your getFeedTitles() function where you set your url variable, and where you make your loader.load method call; it looks like your data provider has only labels but no actual feed url's to set in the URLRequest object.

 

Edit:  See this line in the getSharedData() function in FullRSSReader.as ... it should help you fix things up straight away:

 

 

dp.addItem({label:obj["title"], data:obj["url"]});

 

 

And/or change your second line of code to read:

 

 

newsArr.push({label:"site 1", data:"http://rss.cnn.com/rss/cnn_topstories.rss"});

 

and in your getFeedTitles() function, add these two lines after var urlSmiley Frustratedtring = e.data.data;

 

 

trace("ListEvent data.label property is: " + e.data.label);
trace("ListEvent data.data property is: " + e.data.data);

 

then try clicking on site 1 and site 2 and see what gets traced.

 

 

 

 

Developer
Posts: 1,003
Registered: ‎01-16-2011
My Device: PlayBook (sim)
My Carrier: Rogers

Re: Adding RSS functionality

[ Edited ]

That's awesome, thanks uberschallSamsara.

 

Only problem now though is it isn't grabbing the title names (just make a list where every item is "Title") and when they are clicked I get error "#2044 couldn't resolve host name".  Any suggestions?

 

EDIT: I'm thinking something in here needs to be changed as I'm not using an xml file. Do I need to create one from the url?

 

var rssXML:XML = new XML(URLLoader(e.target).data);
			
			//loop through all of the items and create the object containing the label (title) and the data(link to the article)
			for(var item:String in rssXML.channel.item){
				dp.addItem({label:["title"], data:["url"]});
			}

 

 

- If you like my response/post, or it helped you find an answer you were looking for, please provide a Kudo - white star to the bottom right of this post. -
- Please use the search bar at the top, or check out the PlayBook FAQ's for help getting started -
- Hockey DrillBook -
Developer
Posts: 1,269
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Adding RSS functionality

The strings "title" and "url" from the FullRSSReader example are just the member names for the RSS feed value object's members.  They're user defined in that context; they aren't class member properties of the framework classes.  I'm about to call it a night but I'd say set some more breakpoints and inspect your variables.  Make sure you're really constructing your URLRequest object with a valid URL.  Just to clarify were you not able to get the FullRSSReader.as example code from RIM to work?  I know there were a few incarnations of it posted and I didn't try them all but the one I did try did run on the simulator.  Would suggest reading the sharedobject specific code in FullRSSReader.as in more detail & cross checking vs. API docs; make sure you understand the details.  I also posted this link in a couple of other threads - it's an old tutorial on using sharedobjects - useful to review vs. FullRSSReader.as.

 

If all else fails, I'm sure SkyNet/JRabNet will be back online soon - me, I am mortal and must sleep now.  Smiley Wink

Developer
Posts: 1,269
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Adding RSS functionality

[ Edited ]

Ok just saw your edit - there are potentially 2 levels of data structures you are trying to manage here, assuming you're doing something similar to the FullRSSReader example.  First a list of value objects for the RSS feeds, and second, a list of value objects for the article titles & links from a given feed.  The first data structure is up to you to define but once you request a hunk of XML from a feed URL, you need to grok the structure of that XML in order to grab the article titles and links.  Again a careful review of FullRSSReader will reveal these secrets to you.  Also you should set a breakpoint in your event handler for when your feed URL request completes, and inspect your rssXML variable to verify that it got populated with something that looks as it should vs. the RSS schema of the feed.

 

If you're not familiar with E4X, it's good stuff (too bad it never made it into JavaScript).  There's a chapter on it in this reference (see Chapter 11 "Working with XML")

Developer
Posts: 1,003
Registered: ‎01-16-2011
My Device: PlayBook (sim)
My Carrier: Rogers

Re: Adding RSS functionality

Those are two really great posts with some great info, thanks!

On 0.9.1 I got the FullRSSReader partially working, but haven't been able to since (and I've downloaded about 5 or 6 different code samples). Most of the code I'm using is from the FullRSSReader sample though (the one from early January).

I'm going to sleep on it but hopefully will be able to decipher this tomorrow. Thanks again!
- If you like my response/post, or it helped you find an answer you were looking for, please provide a Kudo - white star to the bottom right of this post. -
- Please use the search bar at the top, or check out the PlayBook FAQ's for help getting started -
- Hockey DrillBook -
Developer
Posts: 1,003
Registered: ‎01-16-2011
My Device: PlayBook (sim)
My Carrier: Rogers

Re: Adding RSS functionality

Ok, so let's see if I understand this correctly:

 

The first piece of data comes from what I specifiy - name, url (shown in code below)

 

                        newsArr = new Array();
			newsArr.push({label:"Engadget", data:"http://www.engadget.com/rss.xml"});
			
			

 

 

The second piece of data comes the actionscript code actually creating an xml file from what it grabs from above, and the then pulling the title and article from the xml, as shown below

 

var rssList:List = new List();
			rssList.x = 0;
			rssList.y = 150;
			rssList.height = 490;
			rssList.width = 300;
			
			var rawRSS:String = URLLoader(e.target).data;
			var dp:DataProvider = new DataProvider();
			var rssXML:XML = new XML(URLLoader(e.target).data);
			
			//loop through all of the items and create the object containing the label (title) and the data(link to the article)
			for(var item:String in rssXML.channel.item){
				dp.addItem({label:["title"], data:["url"]});
			}
			rssList.dataProvider = dp;
			
			//setting the event for each of the items being clicked, this will load up in the web view in the getFeed event
			rssList.addEventListener(ListEvent.ITEM_CLICKED, getArticle);
			
			addChild(rssList);
		

 

Now, if my understanding is correct, I'm not sure what it is I'm missing then and why I just get rssList filled with"title,title, title", and when I click it I get a connection error?

 

- If you like my response/post, or it helped you find an answer you were looking for, please provide a Kudo - white star to the bottom right of this post. -
- Please use the search bar at the top, or check out the PlayBook FAQ's for help getting started -
- Hockey DrillBook -
Developer
Posts: 1,269
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Adding RSS functionality

It looks like you're using a code snippet from the FullRSSReader.as code example's onDataLoad() function, but instead of populating the data provider with value objects that have their label and data properties set to XML nodes from the rssXML variable, you are setting the label and data properties to be the literal strings "title" and "url" respectively.  That's why your rssList displays "title" "title" "title" and why when you click a "title" cell it tries to go to a url of "url" and not a real RSS article link.

 

If you see this soon after I post it, think over the above; I'll post a little more detail in a bit when I get done with some chores here.

Developer
Posts: 1,003
Registered: ‎01-16-2011
My Device: PlayBook (sim)
My Carrier: Rogers

Re: Adding RSS functionality

Thanks for walking me through this. I just realized that moments ago and changed the following code

 

dp.addItem({label:obj["title"], data:obj["url"]});

 To this (so it would pull the xml info:

 

dp.addItem({label:rssXML.channel.item[item].title, data:rssXML.channel.item[item].link});

 

Now I just need to wrap the text in my list so the entire title can be read.

 

 

- If you like my response/post, or it helped you find an answer you were looking for, please provide a Kudo - white star to the bottom right of this post. -
- Please use the search bar at the top, or check out the PlayBook FAQ's for help getting started -
- Hockey DrillBook -
Developer
Posts: 1,269
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Adding RSS functionality

[ Edited ]

Yep, that's it.

 

When you were using this:

 

 

 

dp.addItem({label:["title"], data:["url"]});

 

you were adding a value object literal to your data provider that had  a label property equal to an array with a single string element of "title" and a data property equal to an array with a single string element of "url", on every pass through your loop.  Not what you wanted at all.

 

So is it all working like you want it to now?