import com.xfactorstudio.xml.xpath.*; class PodcastData { static var loadingCount:Number = 0; var podcastURL:String; var parentMovieClip:MovieClip; static var songs:Array; private static var songsCopy:Array; var podcastTitle:String; public var onLoad:Function; function PodcastData(podcastURL:String, parentMovieClip:MovieClip) { this.parentMovieClip = parentMovieClip; loadNow(podcastURL); } function loadNow(podcastURL:String) { var xml:XML; xml = new XML(); xml.ignoreWhite = true; var context = this; xml.onLoad = function(result) { context.processPodcast(xml); } this.podcastURL = podcastURL; loadingCount++; var fullURL:String = "http://www.pseudopsycho.com/radio/proxy.php?url=" + escape(podcastURL); trace(fullURL); xml.load(fullURL); } public static function randomTrack():SongData { if (songs.length == 0) { songs = songsCopy.copy(); } return SongData(songs.pop());//songs[Math.round(Math.random() * (songs.length-1))]; } private function processPodcast(xml:XML):Void { podcastTitle = XPath.selectSingleNode(xml.firstChild, "//channel/title").firstChild.nodeValue; var path:String = "//item/"; var arr = XPath.selectNodes(xml.firstChild, path); if (songs == undefined) { songs = new Array(); } for (var i:Number = 0;i < arr.length;i++) { //var url:String= XPath.arr[i].childNodes[3].attributes.url; var url:String = XPath.selectSingleNode(arr[i],"enclosure").attributes.url; var stitle:String = XPath.selectSingleNode(arr[i],"title").firstChild.nodeValue; var descr:String = XPath.selectSingleNode(arr[i],"description").firstChild.nodeValue; if (url != undefined) { songs.push(new SongData(url, stitle, descr, this)); } } _root.db.text += podcastTitle + " loaded: " + songs.length + " songs\n"; /* var mp3:Sound = new Sound(parentMovieClip); parentMovieClip.onEnterFrame = function() { //trace(mp3.position); } mp3.loadSound(url,true);*/ loadingCount--; songs.shuffle(); songsCopy = songs.copy(); onLoad(); } }