Synchronise Events with Bindings in Flex

I have recently had to delve into the world of Adobe Flex and ActionScript and wanted to share some of my trials and tribulations with it. As I’m not a massive fan of Flash or proprietary technologies I had to assume the work had been assigned to me as a punishment for crimes committed in a previous life. In fact, 2 months in, I’m not entirely convinced what embedded Flash has to offer over conventional html and javascript – especially considering the features available in HTML5. “Meh” pretty much sums up my feelings for Flex – perhaps I’ve been doing too much Java.

Having previously been programming JSF I found Flex quite … different. One notable difference being it’s easy approach to the Observer Pattern with Bindings and another being it’s asynchronous behaviour. As JSF does not have any features comparable to these so this was all unchartered territory for me. In particular, I was experiencing some difficulty with asynchronous calls and the ViewStack. Basically the application was Single-Sign-On and I didn’t want the home view to show until they had been authenticated. Simple right? All you have to do is a bind a Boolean which is set by a CairngormEvent when authentication succeeds. Next problem was that there was some data to show on the home screen. But because every service call is asynchronous the screen would load with a blank area which would only be filled-in once the service call had completed. Well, what’s the point in showing a page unless it’s ready to be shown. I now have 2 conditions that must be true and ChangeWatchers seem to be the only thing that are going to help me.

A capability to synchronise asynchronous events is all I could think of to achieve the desired result. So I created a SynchronisedChangeWatcher class. WARNING – this is an over-engineered solution so I’m not sure if I would recommend using it:

And it’s usage:

So doStuff() will be called when both UserLoggedIn and _CreationComplete properties change – Simplz!

Yet Another tech blog

In my day-to-day activities of fighting evil, feeding the hungry and trying to make the world a better place I do some coding. How my time is divided between each activity I wouldn’t like to say. But when it comes to coding I’ll be honest and admit I don’t know everything. Quite often I have to turn to my friend Google for assistance. I seem to spend as much time reading other people’s personal musings on technology as I do any official documentation. The quality of people’s technology blogs is pretty varied, to say the least. Some are excellent, pioneering, golden examples of what a technology has to offer. Others are a complete and utter worthless pile of crap and I wonder why they took the time to write something (and waste my time reading). Some people have more free time than intelligence I guess.

In an effort to add something of worth to this vast worldwide internet I have decided to start this blog (if other people insist on adding their thoughtless tripe to the internet then why can’t I add my own).