Friday 26 January 2007

Using AMF in Anger

So no sooner had I found a slinky new piece of software to try than an ideal opportunity to test it out comes along! How lucky am I :o)

A request for a quick application to share a list of tasks landed in my in ear this morning, something simple to basically mimic an excel spreadsheet which needed to be shared between several people. Bear in mind we are cross platform so stop shouting "use a shared task list in exchange" because Entourage on the mac is pants, also this might eventually be shared all over the company and we don't let just anyone onto exchange (not because we don't love everyone it just to blinkin slow). So I added a new module to our internal application suite (codenamed Fattie) and set to work creating a new service in AMFPHP.

Now it has to be said that of the 2 main benefits to this new approach the speed of development over XML is huge, I literally needed to declare the table of methods of which there are only 4 and write a very short function for each. So the application broke down to -
1. Fetch a list of all records
2. Fetch a full Entry
3. Fetch a blank entry
4. Save Entry

in all 80 commented lines which I am sure with a bit of inspiration could be halved which would have taken about an hour of unbroken typing if I were ever to get one :o) Add to this 2 tables in the database for the tasks and contractors and the server side is done.

One thing I am still getting used to in Flash is the recordset class, if you are using AMF you really have to use the recordset and this has required a change in my approach to interfaces.


Up to now I have been a big fan of Flashloaded's BIT components for Flash but unfortunately they do not support the recordset as a dataprovider so I have had to dust off the standard Flash version 2 components and bone up on the recordset. That said throwing a quick interface together took about 20 minutes:







Add to this another 20 minutes to create the only dialog box required in the application, that is used to add or edit an entry.





And all that left is a bit of programming to string it all together. As I mentioned before the main difference between how I used to use the BIT Components and the Flash Components is how the data provider is organised. When using a standard array based data provider you can access data using something like component.dataProvider[0].data whereas when dealing with recordsets you have to use component.dataProvider.getItemAt(0).columnName. Seems simple but it probably wasted an hour today in one way or another. Of course now I have dutifully blogged it I shan't forget.

The only thing left to finish off this little app was to take the existing excel worksheet and use the previously blogged technique to force the data into the new MySQL table - sweet :o)

Once finished the other main benefit of AMF kicks in and I can just tell its faster than an XML based equivalent would have been, can't tell you how but I just know.

One improvement which I would have loved to try but I will save for another day is to try and finally get my head around the data binding functions within Flash and using Delta packets to remove the requirement for the dialog box. It would have required some groovy cell renderer's to add the combo boxes to an editable cell but I am sure it could be done.

No comments:

A view from the rack is the personal blog of an IT manager who works for a pub company - hence beer