RSSViewer
http://d.hatena.ne.jp/yorigonomi/rss2 ãåã£ã¦ãã¦è¡¨ç¤ºãã viewerãCDATAããã¾ãparseåºæ¥ãªããããï¼ã®ã§æã§åé¤ããï¼ããããªãjsã§ããã°ããã»ã»ã»
package { import flash.net.URLRequest; import flash.net.URLLoader; import flash.events.*; import flash.display.Sprite; import flash.text.TextField; public class RSSViewer extends Sprite { // public var url:String = 'http://d.hatena.ne.jp/yorigonomi/rss2'; public var url:String = './rss2'; public var rssXML:XML; public var rssOutput:String; public var loader:URLLoader; public var dataWritten:Event; public function RSSViewer():void { var req:URLRequest = new URLRequest(url); loader = new URLLoader(req); loader.addEventListener('complete', xmlLoaded); } public function xmlLoaded(e:Event):void { rssXML = XML(loader.data); var out:XMLList = new XMLList(); for each (var item:XML in rssXML..item) { var title:String = item.title.toString(); var desc:String = item.description.toString(); var link:String = item.link.toString(); out += buildItemHTML(title, desc, link); } rssOutput = '<h1>' + rssXML.channel.title.toString() + '</h1><hr />' + out.toXMLString(); showItems(rssOutput); } public function showItems(body:String):void { var tf:TextField = new TextField(); tf.htmlText = body; tf.y = 10; tf.width = 500; tf.height = 300; tf.backgroundColor = 0xffffff; tf.background = true; addChild(tf); } private function buildItemHTML(title:String, desc:String, link:String):XMLList { default xml namespace = new Namespace(); var body:XMLList = new XMLList(); body += new XML("<b>" + title + "</b>"); var p:XML = new XML("<p>" + desc + "</p>"); var anchor:XML = <a></a>; anchor.@href = link; anchor.font.@color = "#008000"; anchor.font = link; p.appendChild(<br/>); p.appendChild(anchor); body += p; return body; } } }