Nicht neu, aber sehr nützlich und jetzt auch mit Flash CS3 möglich: die Open-Source-ActionScript-Library as3syndicationlib zum Parsen von RSS- und ATOM-Feeds. Für alle Feedtypen wird ein einheitliches Interface genutzt, wie auf die Einträge im Feed zugegriffen werden.
Da die Library für Flex geschrieben wurde und einige Flex-spezifische Klassen nutzt, funktioniert sie standardmäßig nicht mit Flash CS3. Hierzu muss man einige Zeilen im Quellcode austauschen.
Um die Klassen funktionsfähig mit Flash CS3 zu machen, geht man so vor:
- Ersetzen von import mx.utils.StringUtil durch com.adobe.utils.StringUtil (in der Datei „com/adobe/xml/syndication/ParsingTools.as“ und in „com/adobe/xml/syndication/rss/Channel20.as“)
- Man benötigt die Datei DateBase.as von Martin Legris und kopiert sie in „com/adobe/utils“
- Man ersetzt import mx.utils.DateBase durch import com.adobe.utils.DateBase (in der Datei „com/adobe/utils/DateUtil.as“)
Das folgende Beispiel zeigt, wie as3syndicationlib funktioniert. Es wird einfach der Titel (Headline) jedes Feed-Items meines Blog-Feeds in einer Listen-Komponente angezeigt.
[kml_flashembed movie=“/wp-content/uploads/2008/02/as3-syndication-lib.swf“ height=“400″ width=“450″ /]
Der Quellcode lautet:
[as]
import com.adobe.utils.XMLUtil;
import com.adobe.xml.syndication.rss.*;
import flash.events.*;
import flash.net.*;
import fl.data.DataProvider;
import fl.controls.List;
// neuer data provider für die list component
var dp:DataProvider = new DataProvider();
// data provider als quelle angeben
myList.dataProvider = dp;
// neuer loader
var loader:URLLoader = new URLLoader();
//request pointing to feed
var request:URLRequest = new URLRequest(„http://www.video-flash.de/index.php/feed/“);
// event listener (daten geladen / error / security error)
loader.addEventListener(Event.COMPLETE, onDataLoad);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
// laden starten
loader.load(request);
/**
/* Diese Funktion wird aufgerufen, wenn die Daten geladen sind
*/
function onDataLoad(e:Event):void {
//get the raw string data from the feed
var rawRSS:String = URLLoader(e.target).data;
// Validierung mit der XMLUtil.isValidXML API (corelib library)
if(XMLUtil.isValidXML(rawRSS)) {
// neue RSS20 Instanz
var rss:RSS20 = new RSS20();
//Rohdaten parsen
rss.parse(rawRSS);
// all items im Feed in einem Array abspeichern
var items:Array = rss.items;
// jedes Item durchlaufen
for each(var item:Item20 in items) {
dp.addItem( { label: item.title } );
}
}
// nicht valide
else {
txtField.text = „Keine valide XML-Datei.“;
}
}
/**
/* Fehler
*/
function onIOError(e:IOErrorEvent):void {
trace(„IOError : “ + e.text);
}
function onSecurityError(e:SecurityErrorEvent):void {
trace(„SecurityError : “ + e.text);
}
[/as]
[ad]
Hinweis: Es werden auch die Klassen der as3corelib benötigt, die ebenfalls Open Source sind. Man muss die zwei Libraries einfach „zusammenkopieren“.
Link: as3syndicationlib und as3corelib
Link: Parsing RSS 2.0 Feeds in ActionScript 3
Ich habe die as3syndicationlib erweitert, dass sich auch MediaRSS lesen kann. Hier vorab eine allererste Version zum Download …
I’ve extended the as3syndicationlib that it supports Media RSS. Here’s the very first version …
Download: http://www.video-flash.de/wp-content/uploads/2008/02/media-rss.zip
Hello,
I tried using your Media RSS example ad it works grea.One question, when use the youtube rss feed it gives me the title but pure NAN on everything else. Any tips or ideas?
Thanks!
This is the url I tried.
http://youtube.com/rss/global/top_favorites.rss
sorry for the double post
Hi robert. Thanks for your feedback.
The difference is: The YouTube feed doesn’t have a „media:content“ tag. The media rss tags are placed directly within the item tag.
I will have a look at this next week. Perhaps i can figure something out that it doesn’t matter whether the tags are placed within a media:content tag or not.I’ve changed the classes and replaced the zip file above. Now it doesn’t matter whether the media nodes are nested or not. Try it.
If you wish to use the YouTube Data API (from gdata.youtube.com), I made nice wrapper classes to cover everything you need… The project is hosted on Google Code and will be backed up by YouTube shortly. I need to write tutorials before they make it public.
Here is my post:
http://blog.martinlegris.com/?p=83
BTW: I use the JSON format, which you can get from the gdata.youtube.com services by adding alt=json (if my memory serves well).
:)
Ich habe eben die 2 AS3 libs heruntergeladen und in flash cs3 gestetet mit obigem Sourcecode getestet und in der Anleitung zum „patchen der libs“ etwas vermisst was fehlt.
In den Versionen die ich hatte (syndication .85 und core .90)
muss in der Datei com/adobe/syndication/rss/channel20.as in Zeile 41 import mx.utils.DateBase.as durch import com.adobe.utils.DateBase.as ersetzt werden.
Zudem funktionieren sämtliche geter und seter methoden nicht in Flash CS3 Pro man muss direkt mittels public Variablen zugreifen, wie auch oben beim title schon zu sehen ist.
mfg
Sascha
Hallo Sascha,
danke für den Hinweis!
This is very good!
Thanks.
Great work! Thanks..
I’ve added your code to a class and run into an error with the line ..
first.cellRenderer = MultiLineHtmlCell;
and
second.cellRenderer = MultiLineHtmlCell;
1120: Access of undefined property MultiLineHtmlCell.
Ahh just realized MultiLineHtmlCell.as is a class you made ;)
and in the same folder as rss-demo.fla..