Archive | July 2009

Flex AutoComplete: Documentation

Well, it only took me a year but I finally got around to writing up some documentation.

I hope to continue to improve it over time, any feedback you have is greatly appreciated.

Best,
Hillel

Resource Bundles in Flex (new thoughts on the topic)

This is the follow up to a post I wrote a little while ago.

Eliminate the Metadata tag

In the past I was accessing the resource bundle directly in the class. This meant that in I had to add the Metadata tag in every file. A better approach is to create a static class which calls ResourceManager.getInstance(). This way only this class needs to have the Metadata for the bundles. Here’s the static class I’m using.

package 
{
	import mx.resources.ResourceManager;
	
	[ResourceBundle("People")]
	[ResourceBundle("Groups")]
	[ResourceBundle("Framework")]
	public class ResourceUtils
	{
		public static function getString( module:String, key:String, failSilently:Boolean = false ):String
		{
			var value:String = ResourceManager.getInstance().getString( module, key );
			
			if (!value)
			{
				value = ResourceManager.getInstance().getString( "Framework", key );				
			}
			
			if (!value && !failSilently)
			{
				throw new Error( "Error: failed to find value for " + key + " in " + bundleName + " resource bundle" );
			}
			
			return value ? value : "";
		}
	}
}

The application that I’m working on is divided into a number of modules, each has their own resource file. To support this, when requesting a string you also specify the module. If the value isn’t found in the module resource file, then we check the overall framework resource file.

Throw an error if a value isn’t found

I find that I pretty often mistype a key for a string. The default behavior in Flex is to return null, I prefer throw an error in this case as it makes tracking down any missing values much easier. I’ve added the failSilently flag for cases where they may not be a value.

Here’s an example of how you’d use it

<mx:Label text="{ ResourceUtils.getString( Consts.MODULE_PEOPLE, 'addButton' ) }"/>

Static classes for resources in general

This idea of using static classes to reference resources also works well for images. I just saw this in a book I’m reading AdvancED Flex Application Development. It’s a nice, clean approach.

package
{
	[Bindable]
	public class AssetLib
	{
		[Embed(source="buttonUpSkin.png")]
		public static var buttonUpImage:Class;

		[Embed(source="buttonDownSkin.png")]
		public static var buttonDownImage:Class;
	}
}

Hope you find this useful,
Hillel

Flex AutoComplete: Version 1.0

It’s been about a year since first creating the component. I’ve been using it extensively in the applications I work on and it’s been downloaded thousands of times. At this point I’m pretty confident in saying that it works reliably.

Latest version

If you’re already using the component you probably noticed that there’s now a “Latest version” link (rather than the old Demo and Download links). I’ve decided to set up a permanent page on my blog for the component. The important info (ie, the component’s license) is currently scattered amongst the past posts, this way I can keep everything together in one place.

Here’s what’s changed in this release

  • Added support for XMLListCollections: You can now use either an ArrayCollection or an XMLListCollection as the dataProvider.
  • ListBuilder is now a first class component: I’ve refactored the code to support using the ListBuilder on it’s own.
  • Added browserFilterFunction: I’ve added a browserFilterFunction which enables applying a separate filter which is applied to the results shown in the browser. I sometimes show a mix of items in the component. I use this to offer multiple browse options in the actionMenu in the AdvancedAutoComplete.
  • Bug fixes and tweaks: As always, I’ve gone through all of the comments and fixed any issues people have found.

Thanks to e/o who’s spotted bugs, suggested improvements and just been supportive in getting the component to this state. There’s no doubt in my mind that sharing the component with the Flex community has made it far better than it otherwise would have been.

Best,
Hillel

%d bloggers like this: