import mx.utils.Delegate; import mx.controls.TextArea; import com.events.EventBroadcaster; class com.feeds.ProcessRSS { //declare public properties: //the TextArea component which will display the information public var target_txt:Array; //the address of the PHP proxy script public var proxyURL:String; //declare private properties: private var _xml:XML; private var items:Array; private var senderObj:LoadVars; private var loaderID:Number; //constructor function ProcessRSS (target:Array, proxy:String) { target_txt = target; proxyURL = proxy; _xml = new XML(); _xml.ignoreWhite = true; _xml.onLoad = Delegate.create(this, onLoadEvent); } private function onLoadEvent(success:Boolean):Void { if (success) { //terminate any running intervals clearInterval(loaderID); // target_txt.text = "
Click a headline to open that entry in a new window.
XML failed to load.
"; } } public function loadFeed(feedURL:String):Void { //initialization: //terminate any running intervals clearInterval(loaderID); //start with an empty array - replace any previous content items = new Array(); //clear any previous text // target_txt.text = ""; //reset scroll position of TextArea component // target_txt.vPosition = 0; //create LoadVars Object senderObj = new LoadVars(); //assign a value to a property of the LoadVars Object senderObj.rss = feedURL; /* The LoadVars.sendAndLoad method conveniently accepts an XML Object as its target. We can send a string (url) to the PHP proxy script and get an XML document back. */ senderObj.sendAndLoad(proxyURL, _xml, "GET"); /* Use setInterval to monitor load progress every 25 milliseconds. Pass the XML document whose download progress you wish to monitor as the 4th argument. Ue of "this" in "this.loaderID" is critical for telling the loadingFeedback() method in what scope to find the XML object. Thanks to Colin Moock for the code this is based loosely on. */ this.loaderID = setInterval(this, "loadingFeedback", 25, _xml); } /* getNodes(): a recursive method for "walking" the XML tree searching for a match to a node name. This is based on an ActionScript 1 XML prototype by Peter Hall. The method returns an array of all XML nodes that match "name". It is used to populate the "items" array with all nodes in the rss document named "item". Note that a node of nodeType 3 is a text node (a string). We don't want to waste time with that now, so the script skips them. */ private function getNodes(node:XMLNode, name:String):Array { var nodes:Array = new Array(); var c:XMLNode = node.firstChild; while (c) { if (c.nodeType != 3) { if (c.nodeName == name) { nodes.push(c); } nodes = nodes.concat(getNodes(c, name)); } c = c.nextSibling; } return nodes; } /* displayContent() is the method responsible for extracting the data I am interested in (the text content of title, link and description) and formatting it for the TextArea component. */ private function displayContent(source:Array):Void { var entries:Number = source.length; var currentNode:XMLNode; var tempTitle:String; var tempLink:String; var tempDescription:String; for (var i:Number = 0; i"+ tempDescription+"
Requesting Data...
"; } else { // target_txt.text = "Loaded: "+ Math.floor(amtLoaded/1024) + " kilobytes
"; } } }