views:

1986

answers:

3

I'm trying to make an actionscript program that will be able to read an RSS feed and find the title and description of the item. I'm able to load the XML into a variable, but when I try to look at the children nodes of the XML the output tells me there are none. I was able to find a very nice RSS reader explanation made in ActionScript 3, but I need to use ActionScript 2. Any help would be greatly appreciated and let me know If I'm going about this completely the wrong way.

var foo:XML = new XML();
foo.onLoad = function(success:Boolean) {
    trace(foo);
}
foo.load("http://feeds.nytimes.com/nyt/rss/HomePage");

var myArr:Array = new Array();
myArr = foo.childNodes;
trace(myArr.length); //Prints 0
+1  A: 

You need to wait for the XML to load before accessing the data. You have to wait for onLoad to fire before you can access the loaded data.

The simplest change to your code to handle this would be:

var foo:XML = new XML();
foo.onLoad = function(success:Boolean) {
  var myArr:Array = new Array();
  myArr = foo.childNodes;
  trace(myArr.length);
}
foo.load("http://feeds.nytimes.com/nyt/rss/HomePage");
Herms
A: 

I edit your script like that `var foo:XML = new XML(); foo.onLoad = function(success:Boolean) { trace(foo); rss.text = foo; } foo.load("http://feeds.nytimes.com/nyt/rss/HomePage");

var myArr:Array = new Array(); myArr = foo.childNodes; rss.text = myArr.length;`

and please make a dynamic text and give instance name with rss. now you will get all of xml data.

+1  A: 

That was sick. I'm building a Twitter Feed in AS2 (who still needs AS2?) and this totally helped.

drpunchman