Archive for Flex

Exploring Adobe AIR

// September 23rd, 2009 // No Comments » // Actionscript, Computer Software, Flex, Web Development

Recently, I’ve begun developing a Flex application for the desktop using Adobe’s Integrated Runtime (AIR), which is a local library for running Flex applications. One of the most enticing features of AIR applications is the ability to deploy them cross platform with little to no machine-specific code (except perhaps special keystrokes on Mac).  As well, the ability to store data on the client machine is also extremely convenient.  Gone is the worry of keeping a web interface tuned to the application, which can assist in streamlining development into a more user-friendly product.

The only downside to the desktop application is the lack of custom data that would have previously been delivered through the web interface. At least, that’s what I thought.

My exploration into the AIR libraries and many tutorials on the web is that AIR has built-in, for free, SQLite that will allow an application to store and manage data persistently for the lifetime of the application’s existence on the client machine.  There are some minor limitations from a backend development standpoint (like lack of stored procedures), but nothing that should be a surprise to users familiar with ‘lite’ databases.

One of the difficulties with local storage like this is the fact that sensitive data stored through SQLite is not necessarily secure, since it exists on the user’s machine unencrypted. If this were a regular Flex application, all of the data would reside on a database server we own. However, since this on the client’s side, Adobe has a featured called encrypted local store.  The usage and explanation of this feature is out of the scope of this article, but it’s simply a class with static methods that can “get” and “set” values of any kind into encrypted storage. Perfect for storing authentication tokens, and other similar pieces of data.

With data taken care of entirely through AIR, it leaves the developer available to focus to on the user experience with their application. Which for me, has always been a very difficult part to nail down. I’ve written about GUI design previously, and still learn new things everyday either from coworkers, or my own personal experience with software I use frequently.

Hopefully by year end, Flash Builder 4 (the successor to Flex Builder 3) will be released, but more importantly, a program called Flash Catalyst will also be released (likely in tandem). Judging by the demo videos of designer and developer working together to build a Flex interface, mocking up a realistic interface can include physically converting the items in the mockup into flash style definitions.

The more I watch the demonstrations of this technology, the more tempted I am to put my pet project on hold and wait for these to be released.  The trial download for Flash Builder 4 is available from Adobe Labs, though I challenge anyone to use it for the full 30 days and try to return to the previous version. Luckily, my last install of the trial was interrupted by a failed hard drive – I was subsequently saved from the spoils.

Future posts will explain my experiences with my pet project in AIR, which I hope to release to public use as soon as it’s near stable, likely sometime in the new year.

Component Crazy: Handling Your Growing Flex Application

// September 3rd, 2008 // No Comments » // Actionscript, Flex, Web Development

It’s no surprise to developers that the requirements for an application are bound to change, and it’s because of this fact that there are numerous architectures for developing software applications that can ease the process of adding new functionality. 

For Flex specifically, one such architecture is Cairngorm, which has been described here a few times. But as easy as it is to manage important events in the application, even the best architecture fails to simplify a project.  It always gets to a point where there are too many pages to keep track of.

Using a personal example, the backend administration tool that has been in development for my entire tenure at the company (and as such, requirements have shifted dramatically over this time period) has grown to house a fairly large number of major components. Two types of search pages, two types of master-detail pages, a login page, two types of general site maintenance pages and a number of custom renderers and other compents necessary for image retrieval and display.

How does one keep track of all these different areas that a user is supposed to seamlessly surf through?  At first I had a show/hide game going on, but after about 3 different major compents were in use, the process became unmanageable. 

Then I discovered States.

Using the ModelLocator of the Cairngorm architecture, I decided to hold two significant states: the authentication state, and the application state. Both variables declared as strings.

Here’s how the format of the application implements states:

MainApplication.mxml -> Two states: Valid, or invalid.  

When this loads, it dispatches a Cairngorm event to check if a user session exists (via amfphp, to a Zend_Auth controller), if does then the variable for authentication state in ModelLocator is set to “valid”, if not it is set to “invalid”.

In the MainApplication.mxml file, two states are listed such:

1
2
3
4
5
6
7
8
9
10
11
12
<mx:states>
	<mx:State name="invalid">
		<mx:AddChild>
			<mx:LoginComponent />
		</mx:AddChild>
	</mx:State>
	<mx:State name="valid">
		<mx:AddChild>
			<mx:WrapperComponent />
		</mx:AddChild>
	</mx:State>
</mx:states>

The currentState property of the application is bound to the ModelLocator variable for authentication state. So in the event that this property changes to either of these states, the child component will be loaded.

In the case of the administration tool, one of these is a login form and the other is a wrapper component for the next tier of major components. For this example it is called WrapperComponent. Its currentState property is bound to a separate ModelLocator variable to control the general application state.

This solved the problem of having to manage N different components in a complex administration system, and now the code will only need to manage the application state variable and the rest is taken care of.

For added flair, states can also have transitions set to them. Which if done correctly and sparingly, can really add to the look and feel of an application.

Flex Spotlight: Streamzy.com

// July 28th, 2008 // No Comments » // Flex, Web Development

I came across this site the other day and instantly recognized the interface. I also recognized the fact that it had a lot of thought put into the way it was designed. It’s a small, minimalist interface under which you can achieve a lot.

The idea of Streamzy is that you enter search criteria into the box, it returns streaming music in audio OR video form, and you can add and manage playlists (and save these if you choose to register and sign in).  And by “return” it’s not simply providing links, it will play the audio and video streams in their respective custom players.

Kudos to the makers of Streamzy, it’s a very easy to use and useful (albeit probably temporary, see: copyrights) tool to search music while hardly lifting a finger.

Footnote: I was impressed by what I thought might have been a custom Accordion control holding the content grids on the page, but it was in fact a WindowShade control courtesy of the flexlib library.

Workaround for Cached URL Images in Flex

// July 21st, 2008 // 3 Comments » // Flex, Web Development

Just this past week I had found myself wrestling with a Flex application that can crop images on the fly, and display in two different places and two different sizes, a thumbnail of the new image.

One of the biggest headaches in the process was Flash’s caching of the previous URLs when another one has been added in its place. Clearly this causes an inconsistency in ‘what you see is what you get’ (WYSIWYG). So I had to find a solution.

The Image component in Flex has a cachePolicy property (inherited from UIComponent) that will ensure the component’s bitmap values are not cached, but straight URLs are not affected by this.

However, I found a workaround after a good deal of searching the net, and poking and prodding through the nooks and crannies of Flex.

Initially I was going to generate a bitmap of every image brought into the application, but the overhead would have been outrageous, and the simplicity of the program is the service call to generate the new cropped image and return the URL. But it turns out that by adding a random-numbered query string to the end of the incoming URL, the extra value will force the retrieval of the new image.

It worked like a charm, and the only drawback is that all images, changed or unchanged, are re-retrieved with every refresh of the display (in my case, when a component is set to visible, it makes a service call to populate data).

In my case, the value for the URL is kept in in a value object and in the get accessor for its value, I did the following:

1
2
3
4
public function get urlValue():String
{
return _urlValue + "?" + Math.random();
}

A Journey – Part 2: Unit Testing with Cairngorm

// July 13th, 2008 // 2 Comments » // Flex, Web Development

In a previous post I gave an introduction into the complete 180 I’ve done in the web development industry and where I’ve found myself now, and it’s a pretty good place. There have been some mighty challenges, but I feel I’m breaking fairly new ground in the department of Cairngorm asynchronous unit testing. At least, that’s what the results in a Google search would have me believe.

So to continue, I’ll elaborate in more detail about how I accomplished my tests:

  1. In my case, the commands were not separated into service delegates and a delegate is imperative for Cairngorm unit testing
  2. Follow these steps for modifying the FlexUnit source code to assist in giving your delegates a valid IResponder to work with
  3. Build a service component (in our case, /business/Services.mxml) that includes RemoteObjects for your amfphp services
  4. Build a test suite as per the FlexUnit documentation or a great blog entry here from Darron Schall – extremely helpful.
  5. Create a test model class and use it to store values as a private variable in the test class will be cleared after the tearDown() function is hit (regardless if  you’ve specified any variable cleanup)
  6. Build a function in your test suite to call a service from the delegate.

A few things should be kept in mind at this point, you will want to use the IResponder interface in place of Responder in the Cairngorm documentation. This will assist the unit testing process and in turn simplify your test assertions in the test suite. Therefore, in your test suite (which implements IResponder) you will have a result() function where you can run assertions on the service call you just made.

For instance:

1
2
3
private function result(event:Object):void {
assertTrue("Expected a true result.", testModel.var == true);
}

In the event the variable returns a false, the test runner will display a failure message. Otherwise, it is a passed test.

One suggestion for verifying true data rather than just existing data in the model, is to create an object and force it to have the values the service call should return depending on the parameters sent in, which is something I am likely to implement in the near future.

It sounds like a bit of a hack to hardcode a set of values that you know will exist somewhere, but considering the tools available it appears to be the best course of action. I’ve tried a variation on the FlexUnit package called dpUint but found that it wasn’t much clearer on proper implementation for my exact needs.

If there are any Flex developers that have some experience doing exactly this, feel free to let me in on the big secret. Beer’s on me if you can make my job easier.