Andre de Cavaignac

Let's blog it out...

News

For those of you looking for a more personal website and are sad at how boring this site is, find me on Facebook.

Email me

View Andre de Cavaignac's Gatsb Profile

View Andre de Cavaignac's LinkedIn profileView Andre de Cavaignac's profile

(Andre deCavaignac)

Friends

Useful Links

Life With ActionScript and AIR: The Command Pattern Is Your Best Friend

I've recently started a project (top secret!) using the new Adobe Integrated Runtime (AIR), Flex and ActionScript 3.0.  Coming from a .NET and WPF world. this has been a step in a very different direction.  There are a lot of things I don't really love about ActionScript, however it does do its job, and the Adobe AIR deployment strategy (along with its SQLLite database) is pretty damn good.

One of the first things any developer will realize when trying to build a real Rich Internet Application (RIA) in ActionScript is the lack of threading.  This makes doing background tasks very difficult.  ActionScript, and its class library, works largely with callback methods (either from calling setInterval, using a Timer class, calling a SQLConnection or using the HTTPService or other class to make a data call).  From what I can tell, this works much like the Windows message loop, inurrupting synchronous code on your UI thread to process the callback.

While this is great for simple actions (say, a UI that calls a web service or REST service), building a background process (such as a SQL Server synchronization engine) can get complicated.  Due to the number of callbacks you'll receive each time you make a request (to SQLConnection or HTTPService), there is a great amount of complexity in writing simple procedual background processes (that don't freeze up the UI).

To better handle this situation, and ensure that your discrete functions run in the proper order (for example, Authenticate -> Get Data), a command pattern in ActionScript will become your best friend.  You can string together multiple callbacks, and ensure that the code for these operations stay in one logical class.  Furthermore, by using a queue, you can order your commands such that they run synchronously.  This provides much more flexibility than the traditional scripting approach in ActionScript.

Unfortunately, I cannot currently provide code samples, as I do not want to compromise the intellectual property of my project, however, I hope that this will help you get an idea of how to best manage your code and synchronous operations in .NET.

Side Note: If you're using WCF I suggest you use the Basic HTTP Binding with Flex, as FlexBuilder gets confused with .NET Web Services

Leave a Comment

(required) 

(required) 

(optional)

(required)