Skip to main content
Known Participant
March 16, 2012
Answered

Importing RSS feed into Flash

  • March 16, 2012
  • 1 reply
  • 1285 views

Hey there

Firstly thanks for any help on this - much appreciated. I have been creating an rss feed list in flash using the following tutorial: http://alaashaker.wordpress.com/2008/09/09/build-your-own-flash-rss-reader-tutorial-flash-actionscript-30/#comment-932

I get stuck when trying to make each list item clickable to source url. the Description log isn't needed - just a list item --> url

var rssLoader:URLLoader = new URLLoader();

var rssURL:URLRequest =

         new URLRequest("http://rssfeedurl");

rssLoader.addEventListener(Event.COMPLETE, rssLoaded);

rssLoader.load(rssURL);

var rssXML:XML = new XML();

rssXML.ignoreWhitespace = true;

function rssLoaded (evt:Event): void{

rssXML = XML(rssLoader.data) ;

//trace(rssXML);

  

for (var item:String in rssXML.channel.item) {

          liLog.addItem.htmlText= "<a href=" ( {label : rssXML.channel.item[item].title+rssXML.channel.item[item].link}) " ></a>";

 

 

}

}

This topic has been closed for replies.
Correct answer Ned Murphy

Thanks Ned - trying to make sense of it but keep getting an error - Ive gone through all the comments and it seems like there have been issues with this and whatever I try seems to have a syntax error of sorts

function selectLog(evt:Event){

               navigateToURL({data: rssXML.channel.item[item].link}, "_blank");

          }

 

          liLog.addEventListener(Event.CHANGE, selectLog);


The event listener is assigned to the List component so that when you select an item from it, the selection can be processed using and event handler function.  So the event listener would be the way you show it...

    liLog.addEventListener(Event.CHANGE, selectLog);

The event handler function needs to determine which item was selected in the List in order to make use of it for the linking you want.  If you assigned the link to the list as I showed, then you would be looking for the "data" property of the selected item of the list (you could just as easily called it "link" instead of "data")...

   function selectLog(evt:Event){

               var url:String = liLog.selectedItem.data;  // capture the data element (the link)

               navigateToURL(new URLRequest(url)); // open the linked site/page

   }

1 reply

Ned Murphy
Legend
March 16, 2012

If you are adding to a List component, the list component addItem method does not have an htmlText property.  When you assign that data to the List you should be assigning the title to the list exactly the same way as the tutorial.  You could then assign the url as the data element of the object.

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

Then you would create a CHANGE event listener (just like in the tutorial) and event handler function to process selecting one of the List entries.  The event handler function would use the navigateToURL() method and the data element of the selected List item.

Known Participant
March 16, 2012

thanks for your help on this Ned - I've just moved to AS3 from AS2 to handle the rss import so not too sure about adding the event listener to target the link - would really appreciate the script for that last part

thanks!

Ned Murphy
Legend
March 16, 2012

As I said, the event listener would be just like the tutorial shows it.  The event handler would be similarly handled except you are targeting the data property of the List and implementing the navigateToURL function.  If you can work with AS2, you should not need anyone to do this code for you since you have a tutorial to reference already.