A powerful solution for end-to-end Flex development and deployment

Introduction

I’m the sole developer on most of my projects. After years of working with Flex, a handful of architectural frameworks, various server-side languages, and deployment strategies, I’ve come up with a highly productive combination thereof that also performs and scales very well.

Intended Audience

This article is aimed at Flex developers that build larger applications warranting the use of an architectural framework and modules seeking a more productive workflow. This is the most productive solution I’ve found. You can view and download the full source on GitHub
Continue reading

Posted in Solutions | Tagged | 1 Comment

Using complex Objects and ItemEditors with mx.controls.List

Introduction
After working on a simple e-commerce implementation I realized that ItemEditors are fairly poorly documented. I wanted a somewhat purist approach to my implementation meaning I didn’t want to use the default implementation of ListEvent.ITEM_EDIT_END in the List control which depends on naming a labelField and editorDataField. I just wanted to pass data in and out of my renderers and editors without worrying about the Objects themselves.

DataGrid handles complex Objects well, List handles simple Objects well. I needed List to handle a complex Object. It turns out Flex doesn’t make this easy out of the box.

Inside the itemEditorItemEditEndHandler method (mx.controls.List:2613), you’ll find the following:

var newData:Object = itemEditorInstance[editorDataField];
var data:Object = event.itemRenderer.data;

// trace("itemEditEndHandler", event.rowIndex, data);

if (data is String)
{
    if (!(newData is String))
        newData = newData.toString();
}
else if (data is uint)
{
    if (!(newData is uint))
        newData = uint(newData);
}
else if (data is int)
{
    if (!(newData is int))
        newData = int(newData);
}
else if (data is Number)
{
    if (!(newData is int))
        newData = Number(newData);
}
else    // assume some sort of object
{
    bFieldChanged = true;
    try
    {
        data[labelField] = newData;
        if (!(data is IPropertyChangeNotifier))
        {
            // update the underlying collection if a data effect is running
            if (actualCollection)
                actualCollection.itemUpdated(data, labelField);
            else
                collection.itemUpdated(data, labelField);
        }
    }
    catch(e:Error)
    {
        trace("attempt to write to", labelField, "failed.  You may need a custom ITEM_EDIT_END handler");
    }
}

What this boils down to if data is an Object is this:

data[labelField] = itemEditorInstance[editorDataField];

Again, this is great for most inline components or IDropInListItemRenderers with simple data but not for a complex Object and not if you don’t want to be dependent on your Object’s properties.

Solution
Handle the itemEditEnd event in your List like this:

private function handleItemEditEnd( e : ListEvent ) : void {
	//this will override much of the logic in
	//mx.controls.List.itemEditorItemEditEndHandler
	e.preventDefault();

	var list : List = e.currentTarget as List;

	//e.itemRenderer == list.editedItemRenderer
	//if you need to update the renderer explicitly, do it like this
	//list.editedItemRenderer.data = list.itemEditorInstance.data;

	//I just updated the dataprovider
	var i : uint = 0;
	for each( var oldData : Object in list.dataProvider ) {
		if( oldData == list.editedItemRenderer.data ) {
			list.dataProvider.setItemAt(list.itemEditorInstance.data,i);
			break;
		}
		i++;
	}

	//clean up
	list.destroyItemEditor();
}

This is a simple solution to the problem of handling complex Objects in a control designed for simple ones.

Posted in Solutions | Tagged | Leave a comment

Open Graph Protocol and Facebook

Introduction
The Open Graph Protocol (OGP) defines a set of meta tags with which a XHTML document can be marked up. These tags and the protocol itself were drafted by Facebook. I’m not aware of anyone else that consumes this metadata as of this writing.

You should care because this markup is all part of a movement toward a more semantically aware web (article on that to follow). The meta tags allow better integration with Facebook through Facebook’s Like and Share.

The details

Like
Adding a Like button to a OGP marked up document means providing richer content to users. More specifically, when a user Likes a page (page A) on a site not marked up with OGP, not much additional data gets passed into Facebook. Liking page A really means passing along a glorified link into a user’s Facebook stream which goes into the user’s friends’ news feed.

If you’ve been a Facebook user for any amount of time, you know that your Likes quickly become lost not only to you, but especially to your friends. Page B on the other hand has added OGP. When I Like page B, more information than just a title, link, and description of page B is passed along to my stream and into my friends’ news feed.

An example is information like an image designed specifically for Facebook users to see. Being able to select the image ahead of time greatly increases user engagement. A simple image will make your Liked page stand out from the rest.

If you’re page happens to be more meaningful than an article (like a movie, album, band, product, etc.) then that page will be added to the Info section of a user’s profile where it won’t ever be buried again. As an example, try Liking a movie on IMDb. Once you do, you’ll notice that the page you Liked will show up under the movies section of your Info tab. You should also notice the information presented to you when you mouse over the movie you Liked on your profile. Things like the type of content (movie) and the site it came from (IMDb) show up alongside the image IMDb selected to represent the movie you Liked.

Share
The other feature OGP enables through Facebook is Share. Share comes in the form of a bookmarklet or button on a web page that Facebook users can click on to post content to their profile or to their friend’s inbox. Both of these can use OGP to share richer content that might be possible otherwise.

Page administration and Facebook apps
For websites with lots of pages, Facebook allows you to link all of those pages to a Facebook application. Here’s what Facebook’s OGP documentation says

Some sites may have hundreds or even thousands of pages with Open Graph protocol meta data. To handle a site with lots of pages, you can link your pages to your Facebook Platform application. This will enable you to publish stream updates to your pages programmatically. To connect your Page to your Facebook application ID, include your application’s id in the fb:app_id property on your pages

The big picture

The Open Graph Protocol defines a small set of meta tags that can be added to your web pages with ease. It allows you to target your users and integrate your existing Facebook presence with your existing website. If you don’t already have a Facebook presence, it offers a simple way to get on board with social networking. Finally, it allows Facebook users to be more engaged with your website by adding value to the tools they already use.

That’s a more semantically aware web.

Posted in Explanation | Tagged | Leave a comment