Diese Demonstration zeigt, wie man mit Flex die Feeds von kuler einlesen und darstellen kann. Über die Buttons oben kann man einige Standardfeeds auswählen (most popular, etc.). Um die Suchfunktion kurz aufzuzeigen, gibt es daneben ein Suchfeld. Dieses ist so konfiguriert, dass es nur in den Tags nach dem eingegebenen Suchbegriff sucht. Grundsätzlich ermöglicht es die API, in allen Kategorieren zu suchen (Name, Farbwerte, ...)
Hier der Quellcode der Anwendung, die mit dem Flex 3 SDK und ;em>Textmate erstellt wurde:
-
<?xml version="1.0" encoding="utf-8"?>
-
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
-
layout="vertical"
-
width=;1000"
-
height="700"
-
backgroundColor="0x000000"
-
creationComplete="loadFeed('http://kuler.adobe.com/kuler/API/rss/get.cfm?listtype=rating');"
-
>
-
-
<mx:HTTPService id="myFeed"
-
showBusyCursor="true" resultFormat="e4x" result="onResult( event );" />
-
-
<mx:Script>
-
<![CDATA[
-
-
import mx.rpc.events.ResultEvent;
-
import mx.collections.ArrayCollection;
-
-
[Bindable]
-
public var myCollection:ArrayCollection = new ArrayCollection();
-
-
-
// Namespace definieren
-
namespace kulerNS = "http://kuler.adobe.com/kuler/API/rss/";
-
-
private function loadFeed(feedurl:String):void {
-
// Lade RSS Feed
-
myFeed.url=feedurl;
-
myFeed.send();
-
}
-
-
private function onResult( event:ResultEvent ):void {
-
-
var rss:XML = event.result as XML;
-
var i:int;
-
-
myCollection = new ArrayCollection();
-
-
for (i=0; i <rss..kulerNS::themeID.length(); i++) {
-
myCollection.addItem(
-
{themeID: rss..kulerNS::themeID[i],
-
themeTitle: rss..kulerNS::themeTitle[i],
-
themeImage: rss..kulerNS::themeImage[i],
-
swatchHexColor0: rss..kulerNS::swatchHexColor[i*5+0],
-
swatchHexColor1: rss..kulerNS::swatchHexColor[i*5+1],
-
swatchHexColor2: rss..kulerNS::swatchHexColor[i*5+2],
-
swatchHexColor3: rss..kulerNS::swatchHexColor[i*5+3],
-
swatchHexColor4: rss..kulerNS::swatchHexColor[i*5+4]
-
});
-
}
-
-
}
-
-
-
]]>
-
</mx:Script>
-
-
-
-
-
<!-- ::::::::::::::::::::::::: Buttons ::::::::::::::::::::::::: -->
-
-
-
<!-- ::::::::: kuler ::::::: -->
-
<mx:Image source="kuler-logo.gif" />
-
-
<mx:HBox id="hBoxButtons1" horizontalAlign="left">
-
<mx:Label color="0xFFFFFF" text="Feed/Source:" />
-
<mx:Button label="Highest-rated" click="loadFeed('http://kuler.adobe.com/kuler/API/rss/get.cfm?listtype=rating');" />
-
<mx:Button label="Most popular" click="loadFeed('http://kuler.adobe.com/kuler/API/rss/get.cfm?listtype=popular');" />
-
<mx:Button label="Most recent" click="loadFeed('http://kuler.adobe.com/kuler/API/rss/get.cfm?listtype=recent');" />
-
<mx:TextInput id="myTextInput" enter="loadFeed('http://kuler.adobe.com/kuler/API/rss/search.cfm?searchQuery=tag:' + myTextInput.text );"/>
-
<mx:Button label="Search Tag" click="loadFeed('http://kuler.adobe.com/kuler/API/rss/search.cfm?searchQuery=tag:' + myTextInput.text );" toolTip="Specify a simple term. The search looks for that term in tags."/>
-
</mx:HBox>
-
-
-
-
-
<!-- ::::::::::::::::::::::::: Datagrid ::::::::::::::::::::::::: -->
-
-
<mx:DataGrid id="myDataGrid" dataProvider="{myCollection}" width="100%" height="200"
-
>
-
<mx:columns>
-
-
<mx:DataGridColumn dataField="themeID" headerText="ID" width="30"/>
-
<mx:DataGridColumn dataField="themeTitle" headerText="Title" width="60"/>
-
<mx:DataGridColumn dataField="swatchHexColor0" headerText="hex0" width="30"/>
-
<mx:DataGridColumn dataField="swatchHexColor1" headerText="hex1" width="30"/>
-
<mx:DataGridColumn dataField="swatchHexColor2" headerText="hex2" width="30"/>
-
<mx:DataGridColumn dataField="swatchHexColor3" headerText="hex3" width="30"/>
-
<mx:DataGridColumn dataField="swatchHexColor4" headerText="hex4" width="30"/>
-
<mx:DataGridColumn dataField="themeImage" headerText="Preview" width="100">
-
<mx:itemRenderer>
-
<mx:Component>
-
<mx:Image source="{data.themeImage}" />
-
</mx:Component>
-
</mx:itemRenderer>
-
</mx:DataGridColumn>
-
-
</mx:columns>
-
</mx:DataGrid>
-
-
<!-- ::::::::::::::::::::::::: Display ::::::::::::::::::::::::: -->
-
-
<mx:HBox id="hbBox" width="100%">
-
<mx:Box id="box0" width="20%" height="300" backgroundColor="{int('0x' + myDataGrid.selectedItem.swatchHexColor0)}" />
-
<mx:Box id="box1" width="20%" height="300" backgroundColor="{int('0x' + myDataGrid.selectedItem.swatchHexColor1)}" />
-
<mx:Box id="box2" width="20%" height="300" backgroundColor="{int('0x' + myDataGrid.selectedItem.swatchHexColor2)}" />
-
<mx:Box id="box3" width="20%" height="300" backgroundColor="{int('0x' + myDataGrid.selectedItem.swatchHexColor3)}" />
-
<mx:Box id="box4" width="20%" height="300" backgroundColor="{int('0x' + myDataGrid.selectedItem.swatchHexColor4)}" />
-
</mx:HBox>
-
-
-
</mx:Application>
Link: kuler API Demonstration

Ein Kommentar zum Beitrag "kuler API & Flex: Feeds einlesen und darstellen"
Hier ein ergänzender Link: “parsing the kuler rss feed using flex” von Peter deHaan
http://blog.flexexamples.com/2007/08/22/parsing-the-kuler-rss-feed-using-flex/
Schreibe einen Kommentar