Research Project: Starting with flex

Sunday, January 18, 2009

It was 2009 in the time and we have started with our main project (bachelor thesis). We ended up with an exciting project that is delivered by Brook Consulting. The project has been named the AirDog .

In essence, this project goes on to develop a reporting and statistical software to data provided by the Norwegian Kennel Club (NKK).

The two coaches that we have been awarded by the Brook called Erlend and Ole. They are members of bird dog clubs Pointer and Breton, thus the program will primarily be directed at these two clubs in the first place.

We will use the languages ​​flex and php. We have some experience with PHP before, but flex is something completely new.

After some testing I ended up with this:

feedflex

feed flex states and one can say that I miss, but learned a lot. To subscribe to a feed by feed flex you need a crossdomain.xml in the root of the domain feed comes from. It also needs to be set up so that one can access from the outside.

The reason I did not notice this before the program was "finished" was that in debug mode there is no requirement for crossdomain.xml introduced. It was only when I sent the application to Tore (school friend) that I noticed that something was wrong. For those who want to access files and information outside the domain as your flex app runs so read more about here: Flash / Flex Tutorial - How to Create a crossdomain.xml file.

The source code for feed flex:

FeedFlex.mxml

<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initData()" width="100%" height="100%"> </mx><mx :Script> < ![CDATA[ import mx.rpc.events.FaultEvent; import mx.formatters.DateFormatter; import mx.resources.ResourceBundle; import mx.collections.*; import mx.controls.*; import mx.events.*; [Bindable] public var localFeeds:ArrayCollection = new ArrayCollection(); public var lsofeeds:LSOHandler; public function initData():void { lsofeeds = new LSOHandler("feeds"); if (lsofeeds.getObjects()) { localFeeds = lsofeeds.getObjects(); } } private function addFeed():void { var df:DateFormatter = new DateFormatter(); df.formatString="DD-MMM-YYYY"; var o:Object = {name:addAName.text, url:addAurl.text, date:df.format(new Date())}; lsofeeds.addObject(o); localFeeds = lsofeeds.getObjects(); addAName.text = ""; addAurl.text = ""; } private function removeFeed(eventObj:CloseEvent):void { if (eventObj.detail==Alert.OK) { if (myGrid.selectedIndex > -1) { localFeeds.removeItemAt(myGrid.selectedIndex); } } } public function clickHandler(event:ItemClickEvent):void { if (event.index == 0){ httpRSS.url = myGrid.selectedItem.url; httpRSS.send(); } else if (event.index == 1) { myGrid.editable = true; } else { var objAlert:Alert = Alert.show( "Vil du slette " + myGrid.selectedItem.url, "Slette?", Alert.OK | Alert.CANCEL, this, removeFeed, null, Alert.OK); } } private function feedFaultHandler(event:FaultEvent):void { Alert.show("Problem med å laste inn feeden\n" + "Problemet kan komme av at det ikke er en feed url som er skrevet inn.", "Feed problem"); } ]]> </mx> <mx :HTTPService id="httpRSS" resultFormat="object" fault="feedFaultHandler(event);" /> <mx :VBox id="theBox" height="100%" width="80%" horizontalAlign="center"> </mx><mx :Panel id="adder" title="RSS URL" width="100%"> </mx><mx :Form width="100%"> </mx><mx :Canvas height="57"> <mx :Label id="labelUrl" text="URL:" x="0" y="29"/> <mx :Label id="labelNavn" text="NAVN:" x="0" y="1"/> <mx :TextInput id="addAName" width="287" borderStyle="solid" x="46" y="0"/> <mx :TextInput id="addAurl" width="287" borderStyle="solid" x="46" y="25"/> <mx :Button label="Legg til" click="addFeed()" x="341" y="25"/> </mx> <mx :DataGrid id="myGrid" width="100%" height="133" dataProvider="{localFeeds}"> </mx><mx :columns> <mx :DataGridColumn headerText="Navn" dataField="name" /> <mx :DataGridColumn headerText="Url" dataField="url" /> <mx :DataGridColumn headerText="Dato lagt inn" dataField="date" /> </mx><mx :DataGridColumn headerText="Slett" editable="false"> </mx><mx :itemRenderer> </mx><mx :Component> </mx><mx :ButtonBar itemClick="outerDocument.clickHandler(event)"> </mx><mx :dataProvider> </mx><mx :Array> </mx><mx :String>Last inn</mx> <mx :String>Rediger</mx> <mx :String>Slett</mx> <mx :Panel id="reader" title="RSS innhold" width="100%"> </mx><mx :DataGrid id="entries" width="100%" dataProvider="{httpRSS.lastResult.rss.channel.item}" itemClick="{body.htmlText=httpRSS.lastResult.rss.channel.item[entries.selectedIndex].description}"> </mx><mx :columns> <mx :DataGridColumn dataField="title" headerText="Tittel" /> <mx :DataGridColumn dataField="pubDate" headerText="Dato" /> </mx> <mx :TextArea id="body" editable="false" width="100%" height="100"/> 

LSOHandler.as

 // ActionScript file package { import mx.collections.ArrayCollection; import flash.net.SharedObject; public class LSOHandler { private var mySO:SharedObject; private var ac:ArrayCollection; private var lsoType:String; public function LSOHandler(s:String) { init(s); } private function init(s:String):void { ac = new ArrayCollection(); lsoType = s; mySO = SharedObject.getLocal(lsoType); if (getObjects()) { ac = getObjects(); } } public function getObjects():ArrayCollection { return mySO.data[lsoType]; } public function addObject(o:Object):void { ac.addItem(o); updateSharedObjects(); } private function updateSharedObjects():void { mySO.data[lsoType] = ac; mySO.flush(); } } } 

Used Adobe - Flex 3 LiveDocs to find most of the information you need to get started.

It helped in particular to understand the shared object, the Flex's kind of cookie. For more information about how you use it you can check out this link: http://livedocs.adobe.com/flex/3/html/help.html?content=lsos_3.html

Check out our project page http://prosjekt.mindre.net

Categories → Flex

    Write a comment