Rss reader problem

Hello all. I seem to be having a little problem with my rss reader. So far everything i needed it to do it does excpt 1 thing. i can not get the first item to deiplay by default.

heres my doce


//lb = list box component
//ta = text area component
 
var loader:URLLoader = new URLLoader();
loader.addEventListener (Event.COMPLETE, onLoaded);
 
lb.addEventListener (Event.CHANGE, itemChange);
 
function itemChange (e:Event):void
{
 ta_txt.htmlText = lb.selectedItem.data;
}
 
var xml:XML;
function onLoaded (e:Event):void
{
lb.selectedItem= 0;
lb.selectedIndex = 0;
ta_txt.htmlText = xml.item[lb.selectedIndex].description;
 xml = new XML(e.target.data);
 var il:XMLList = xml.item;
 for (var i:uint=0; i<il.length(); i++)
 {
  lb.addItem ({data:il.description.text()*,
  label:il.title.text()*});
 }
}
//trace(xml.item[lb.selectedIndex].description);
 
loader.load (new URLRequest("http://domain.net/screensaver/feed-alternate.xml"));
view_btn.addEventListener(MouseEvent.CLICK, viewOnline);
 
function viewOnline(event:MouseEvent):void
{
 navigateToURL(new URLRequest(xml.item[lb.selectedIndex].link));
}

any one have an idea of how i can accive this?

– just figured it out fix is in the edeit Thanks again guys

Here’s the first thing that I noticed.


ta_txt.htmlText = xml.item[lb.selectedIndex].description;
 xml = new XML(e.target.data);

You’re assigning the htmlText of your text field before you declared what “xml” is. I’m surprised it’s not throwing an error because of that. If it’s really that simple of a problem, then you should be able to just swap those two lines and have it working for you.

Also, I’d set the selectedItem/Index of your list box AFTER you’ve filled it with all of the items. So maybe move around the lines in your complete handler to this:


function onLoaded (e:Event):void
{
      xml = new XML(e.target.data);
      var il:XMLList = xml.item;

      for (var i:uint=0; i<il.length(); i++)
      {
            lb.addItem ({data:il.description.text()*, label:il.title.text()*});
      }
 
      lb.selectedItem= 0;
      lb.selectedIndex = 0;
      ta_txt.htmlText = xml.item[lb.selectedIndex].description;

}

Just a hunch after a quick glance. Hope it helps!

Thanks for the help thats what i wound up doing. I took a breather and came back 5 mins later and i saw the answer clear as day. It was as simple as moving lines around just as you said.

Thanks again

Glad to hear it’s working for you. :slight_smile: Happy to help.