home subscribe to email updates subscribe to RSS updates

Flex: First Steps

This week I'm spending a little time looking into Flex and revising the AS3 lessons of a few months ago.

Whilst actually figuring out where to start wasn't so easy, the actual learning process and overall Flex structure was surprisingly straight forward. Whilst I've only really travelled .001% of the way towards being a Flex master, I'm happy to say that my first impressions were positive. They just might make an RIA developer out of me yet!

I decided that the easiest place to start was probably an RSS reader... so that's what we've got here. I've also posted the code so that you guys can tell me if I've gone wrong (or could've done something more efficiently) and perhaps it will be of service to the next AS2 jockey that wants to look into the world of Flex.

It took me a few hours to go through some online lessons and figure all of this out but I'd guess that this sort of application would only take you 5-10 mins if you knew what you were doing. There is so little code that it's almost rude... but the trade-off is that what you see below is 260K. Ouch!

... and here's the code or if you prefer, download the mxml file here.

Actionscript:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application
  3.     xmlns:mx="http://www.adobe.com/2006/mxml"
  4.     layout="absolute"
  5.     width="440"
  6.     height="440"
  7.     horizontalAlign="center"
  8.     verticalAlign="middle"
  9.     creationComplete="feed.send();"
  10.     >
  11.  
  12.  
  13.     <mx:Script>
  14.         <![CDATA[
  15.            
  16.             import flash.net.navigateToURL;
  17.             import mx.rpc.events.FaultEvent;
  18.             import mx.rpc.events.ResultEvent;
  19.             import mx.controls.Alert;
  20.            
  21.             [Bindable]
  22.             private var _photoFeed:XML;
  23.             [Bindable]
  24.             private var _selectedLink:String;
  25.            
  26.            
  27.             // Define and use the RSS 2 namespace
  28.             private namespace rss2 = "http://backend.userland.com/rss2";
  29.             use namespace rss2;
  30.            
  31.            
  32.             private function resultHandler(event:ResultEvent):void {
  33.                 this._photoFeed = event.result as XML;
  34.             }
  35.            
  36.            
  37.             private function faultHandler(event:FaultEvent):void {
  38.                 Alert.show(event.fault.message, "Could not load feed!");
  39.             }
  40.            
  41.            
  42.         ]]>
  43.     </mx:Script>
  44.    
  45.  
  46.     <!-- define the HTTP service -->
  47.     <mx:HTTPService id="feed" useProxy="false"
  48.         url="http://feeds.feedburner.com/MichaelBattle-WorkPlay"
  49.         resultFormat="object"
  50.         result="resultHandler(event);"
  51.         fault="faultHandler(event);"
  52.         showBusyCursor="true"
  53.         />
  54.  
  55.  
  56.     <mx:Panel x="10" y="10" width="420" height="420" layout="absolute" title="Michael Battle - Work &amp; Play" horizontalAlign="center" verticalAlign="middle" cornerRadius="5" fontSize="15">
  57.    
  58.         <mx:DataGrid id="headlines"
  59.             dataProvider="{feed.lastResult.rss.channel.item}"
  60.             click="{itemContent.htmlText=feed.lastResult.rss.channel.item[headlines.selectedIndex].description}"
  61.             showHeaders="false" width="380" height="171" x="10" y="10" cornerRadius="5" borderThickness="2" fontSize="12">
  62.        
  63.             <mx:columns>
  64.                 <mx:DataGridColumn dataField="title" />
  65.             </mx:columns>
  66.            
  67.         </mx:DataGrid>
  68.        
  69.        
  70.         <mx:TextArea x="10" y="199" width="380" height="121" id="itemContent" paddingLeft="5" paddingRight="5"
  71.             editable="false" wordWrap="true" enabled="true" cornerRadius="5" borderThickness="2" backgroundColor="#f7f8f9" fontSize="12"/>
  72.         <mx:HRule x="10" y="189" width="380"/>
  73.            
  74.    
  75.         <mx:ControlBar>
  76.             <mx:Button x="10" y="374" label="SELECT POST AND CLICK HERE TO READ MORE"
  77.                 click="{navigateToURL(new URLRequest(feed.lastResult.rss.channel.item[headlines.selectedIndex].link))}"
  78.                 width="400" height="30" fontSize="12"
  79.                 />
  80.         </mx:ControlBar>
  81.                    
  82.     </mx:Panel>
  83.    
  84. </mx:Application>

The next Flex milestone I'm going to aim for is a simple Twitter app.

If you're trying to learn too, here are some links that I found useful:

If you've got some tips or links, I'd really appreciate your words of wisdom.


« Remix this!
AddThis Social Bookmark Button

Related Posts:

Leave a Comment



« Remix this!