<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ladysign Dev Blog &#187; flex xml</title>
	<atom:link href="http://www.ladysign-apps.com/blog/tag/flex-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ladysign-apps.com/blog</link>
	<description>Girls can code.</description>
	<lastBuildDate>Mon, 12 Dec 2011 16:58:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flex: Create a lastfm artist playcount app</title>
		<link>http://www.ladysign-apps.com/blog/code/flex-code/flex-create-a-lastfm-artist-playcount-app/</link>
		<comments>http://www.ladysign-apps.com/blog/code/flex-code/flex-create-a-lastfm-artist-playcount-app/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 15:33:58 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[adobe flex]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[flex xml]]></category>
		<category><![CDATA[last fm]]></category>
		<category><![CDATA[lastfm]]></category>
		<category><![CDATA[lastfm API]]></category>
		<category><![CDATA[playcount]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://ladysign-apps.com/blog/?p=388</guid>
		<description><![CDATA[<p><strong>Difficulty:</strong> 3 out of 5 stars</p>
<p>I have to say. I love music, so I adore <a href="http://www.last.fm" target="_blank">LastFm</a>. But I&#8217;m also a lover of Adobe and it&#8217;s application Flex. So l[......]</p><p class='read-more'><a href='http://www.ladysign-apps.com/blog/code/flex-code/flex-create-a-lastfm-artist-playcount-app/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p><strong>Difficulty:</strong> 3 out of 5 stars</p>
<p>I have to say. I love music, so I adore <a href="http://www.last.fm" target="_blank">LastFm</a>. But I&#8217;m also a lover of Adobe and it&#8217;s application Flex. So let&#8217;s learn something about Flex, XML webservices and the LastFM API. We are gonna create (with Flex Builder 3), a simple but cool application which loads your artist and playcount information from your LastFM account.</p>
<p>First create a LastFM developer account, it will give you the LastFM API_KEY.<br />
It will also grand you access to the big LastFM API, with LastFM methods and webservices:<br />
<a href="http://www.last.fm/api/account">Last FM API Dev account</a>.</p>
<p>When you have a LastFM API account, you can access the following URL with your details ([your_key_here] prefill with your api_key and [last_fm_user] prefill with the lastfm username from who you want to retrieve the artist and playcount info from), to receive the XML of your artist info/playcount.</p>
<pre class="brush: jscript; title: ;">
http://ws.audioscrobbler.com/2.0/?method=library.getartists&amp;api_key=[your_key_here]&amp;user=[last_fm_user]
</pre>
<p>Check this XML, and see its structure. (we need this structure in Flex!)</p>
<pre class="brush: xml; title: ;">
&lt;lfm&gt;
  &lt;artists&gt;
     &lt;artist&gt;
       &lt;name&gt;Guano Apes&lt;/name&gt;
       &lt;playcount&gt;100&lt;/playcount&gt;
       ...
    &lt;/artist&gt;
     &lt;artist&gt;
       &lt;name&gt;Felix the housecat&lt;/name&gt;
       &lt;playcount&gt;50&lt;/playcount&gt;
       ...
    &lt;/artist&gt;
  &lt;/artists&gt;
&lt;/lfm&gt;
</pre>
<p>Now you have your api_key let&#8217;s run Adobe Flex, and create a Flex Project.<br />
Add the following code into the source tab:</p>
<p>This will start a nice Flex panel, with the title: &#8220;Favourite Artists&#8221;.</p>
<p><?xml version="1.0" ?><br />
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"><br />
   <mx:Panel id="reader" title="Favorite Artists" width="650" height="450" layout="absolute"></p>
<p>   </mx:Panel><br />
</mx:Application></p>
<p>Now add the webservice: HTTPService, with the previous mentioned url to the Lastfm XML, and give it the idname: &#8220;fetchData&#8221;. I added this code above my panel code.<br />
Please note that you have to encode the &#8220;&#038;&#8221; signs, so Flex sees the URL as one line.</p>
<pre class="brush: jscript; title: ;">
&amp;#38;
</pre>
<p>	<mx:HTTPService id="fetchData" url="http://ws.audioscrobbler.com/2.0/?method=library.getartists&#38;api_key=[your_key_here]&#38;user=[lastfm_username]" resultFormat="object" /></p>
<p>We can now add a datagrid, for the Artist column (see headerText), we want to prefill this with<br />
the xml node &#8216;name&#8217; (lfm.artists.artist.name), and the playcount column with &#8216;playcount&#8217; (lfm.artists.artist.playcount):</p>
<p>	<mx:DataGrid id="entries" width="630" dataProvider="{fetchData.lastResult.lfm.artists.artist}" x="-0.15" y="7.1054274E-15" height="366.4394"><br />
	  <mx:columns><br />
	    <mx:Array><br />
	      <mx:DataGridColumn dataField="name" headerText="Artist" /><br />
	      <mx:DataGridColumn dataField="playcount" headerText="Playcount" /><br />
	    </mx:Array><br />
	  </mx:columns><br />
	</mx:DataGrid></p>
<p>And the button to fetch the xml data. Use your HTTPService id .send() method:</p>
<p>	<mx:Button label="Get favourite artists" click="{fetchData.send()}" x="9.05" y="375"/></p>
<p>Okay, let&#8217;s build and run it in Flex. Wow!</p>
<p>Here&#8217;s the complete code:</p>
<p><?xml version="1.0" ?><br />
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"></p>
<p>	<mx:HTTPService id="fetchData" url="http://ws.audioscrobbler.com/2.0/?method=library.getartists&#38;api_key=[your_key_here]&#038;&#38;user=[lastfm_username]" resultFormat="object" /></p>
<p>	<mx:Panel id="reader" title="Favorite Artists" width="650" height="450" layout="absolute"></p>
<p>	<mx:DataGrid id="entries" width="630" dataProvider="{fetchData.lastResult.lfm.artists.artist}" x="-0.15" y="7.1054274E-15" height="366.4394"><br />
	  <mx:columns><br />
	    <mx:Array><br />
	      <mx:DataGridColumn dataField="name" headerText="Artist" /><br />
	      <mx:DataGridColumn dataField="playcount" headerText="Playcount" /><br />
	    </mx:Array><br />
	  </mx:columns><br />
	</mx:DataGrid></p>
<p>	<mx:Button label="Get favorite artists" click="{fetchData.send()}" x="9.05" y="375"/></p>
<p>	</mx:Panel><br />
</mx:Application></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ladysign-apps.com/blog/code/flex-code/flex-create-a-lastfm-artist-playcount-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

