I am working on a Flash based RSS reader and trying to extract just the <img src="…"> code out of the <description> tag, but I haven’t found a solution. I tried doing a trace, but that comes up with a undefined for data.
Here is my code so far and RSS XML example:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);
lb.addEventListener(Event.CHANGE, itemChange);
function itemChange(e:Event):void
{
tb.htmlText = lb.selectedItem.data;
ta.htmlText = "<a href=\"" + lb.selectedItem.link + "\">" + lb.selectedItem.label + "</a>";
}
var xml:XML;
function onLoaded(e:Event):void
{
xml = new XML(e.target.data);
var il:XMLList = xml.channel.item;
for(var i:uint=0; i<il.length(); i++)
{
lb.addItem({data:il.description.text()*, link:il.link.text()*,
label:il.title.text()*});
}
}
loader.load(new URLRequest("http://www.siteurl.com/rss.xml"));
<channel>
<title>Site Name</title>
<description></description>
<link>http://www.siteurl.com</link>
<lastBuildDate>Sat, 01 Mar 2008 22:02:43 +0000</lastBuildDate>
<generator>FeedCreator 1.7.2</generator>
<image>
<url>/images/logo.png</url>
<title>Site Name</title>
<link>http://www.siteurl.com</link>
<description><![CDATA[Site Name]]></description>
</image>
<item>
<title>Title of First Feed Item</title>
<link>http://www.siteurl.com/link.html</link>
<description><![CDATA[<img src="http://www.siteurl.com/images/stories/users/logo.jpg" align="left" border="0" alt="" /> This is a sample article with a preceeding picture.</description>
</item>
<channel>
So under the <item><description>, it has a preceeding image, I just want to pull the Image URL and drop everything else.
Thanks,
Corey