读取一个RSS种子,并输入到屏幕上

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	
	public class SampleLoadXML extends Sprite
	{
		private var titleTxt:TextField;
		
		public function SampleLoadXML()
		{
			super();
			var targetUrl:String="http://feed.feedsky.com/jiaren";
			
			var request:URLRequest=new URLRequest(targetUrl);
			var Loader:URLLoader=new URLLoader();
			
			Loader.addEventListener(Event.COMPLETE,onComplete);
			
			try{
				trace("loading。。。。");
				Loader.load(request);
			}
			catch(error:Error)
			{
				trace("unable to load URL!");
			}
			
			titleTxt=new TextField();
			titleTxt.autoSize="left";
			
			addChild(titleTxt);
			
		}
		
		private function onComplete(evt:Event):void{
			trace(evt.target.data is String);
			var resultXML:XML=new XML(evt.target.data);
			
			var titleList:XMLList=resultXML.channel.item.title;
			
			for each(var title:XML in titleList)
			titleTxt.appendText("*"+title+"\n");
		}
	}
}

你可能感兴趣的:(读取一个RSS种子,并输入到屏幕上)