- 作者:xiaoxiao
- 发表时间:2020-12-23 11:00
- 来源:未知
AS2 Code://============================================================//Written by Giacomo Huang, MCI Studio, http://mci.name//Reference: http://www.flashphp.org/weblog/site///beta 2//2004-8-2//============================================================import mx.events.EventDispatcher;class com.mcistudio.RssReader extends MovieClip {?public var rssXML;?private var rssAttributes:Object;?private var itvObj;?private var intervalID;?private var rssItems:Array;?private var rssImages:Array;?public var addEventListener:Function;?public var removeEventListener:Function;?private var dispatchEvent:Function;?public function RssReader() {??mx.events.EventDispatcher.initialize(this);?}?public function load(rss_url:String):Void {??rssXML = new XML();??rssXML.ignoreWhite = true;??rssXML.parent = this;??rssXML.load(rss_url);??itvObj = new Object();??itvObj.parent = this;??itvObj.interval = function() {???this.parent.dispatchEvent({type:"onProgress", target:this.parent});??};??intervalID = setInterval(itvObj, "interval", 1);??rssXML.onLoad = function(s) {???if (s) {????this.parent.getRssContent();????clearInterval(this.parent.intervalID);????this.parent.dispatchEvent({type:"onLoaded", target:this.parent});???} else {????clearInterval(this.parent.intervalID);????this.parent.dispatchEvent({type:"onFailed", target:this.parent});???}???this.parent.onRssLoaded(s);??};?}?private function getRssContent():Boolean {??rssAttributes = {};??rssItems = [];??rssImages = [];??var node = rssXML.firstChild.childNodes[0].childNodes;??for (var i = 0; i ???var sNode = node[i]; ???switch (sNode.nodeName) { ???case "item" : ????var obj = {}; ????for (var j = 0; j ?????obj[sNode.childNodes[j].nodeName] = sNode.childNodes[j].childNodes[0].nodeValue; ????} ????rssItems.push(obj); ????break; ???case "image" : ????var obj = {}; ????for (var j = 0; j ?????obj[sNode.childNodes[j].nodeName] = sNode.childNodes[j].childNodes[0].nodeValue; ????} ????rssImages.push(obj); ????break; ???default : ????rssAttributes[sNode.nodeName] = sNode.childNodes[0].nodeValue; ????break; ???} ??} ??return true; ?} ?public function getAttributes():Object { ??return rssAttributes; ?} ?public function getItems():Array { ??return rssItems; ?} ?public function getImages():Array { ??return rssImages; ?} ?public function get bytesLoaded() { ??return rssXML.getBytesLoaded(); ?} ?public function get bytesTotal() { ??return rssXML.getBytesTotal(); ?} ?public function get percent() { ??if (bytesTotal == 0 || bytesLoaded == 0 || isNaN(bytesLoaded) || isNaN(bytesTotal)) { ???return 0; ??} else { ???return Math.floor((bytesLoaded/bytesTotal)*100); ??} ?} }