Saturday, September 26, 2009

Deep linking in Flex

A Deep link can be loosely defined as a link to a web page other than the main or home page of a web site. Jakob Nielsen, one of the foremost gurus on web usability has said 'Deep Linking is Good Linking'. He also points out when it is good to avoid deep linking.

Flex applications do not work like traditional web applications. Navigating to different states/views of a Flex application happens internally and does not open a new URL. In fact, opening a new URL (a new page load) would mean losing the state of the application. Working within a single URL poses problems in enabling common web page features like bookmarking and back-forward navigation.

To implement these features, the different states / views of a Flex application are represented using real or pseudo named anchors. For instance, if the main page is www.mywebsite.com, a view that represents the customers information would be www.mywebsite.com/#customers or www.mywebsite.com/#/customers . Anything after the # is called a URL fragment. These fragments are used in the two way communication between the browser and the flex application - the Flex application informs the browser of a change or user interaction so the browser can update the URL to reflect this action and the browser informs the Flex application of a change in the URL so that the application updates its state to reflect the change. All this happens without a page reload.

This kind of deep linking in Flex is implemented in various ways.

Flex 3.0 itself implements deep linking using the BrowserManager and URLUtil classes. The BrowserManager class provides methods for setting the browser page title, setting and getting URL fragments and listens for change events in the web page URL. The URLUtil class provides methods for processing fragments – to convert the name-value anchor information into objects or strings as necessary. Read more about these features in this article titled Flex 3: Feature Introductions: Deep Linking. Some limitations in this implementation are that the application has be initialised before you can pass any URL fragment references to it and BrowserManager is not yet supported and tested for all browsers.

A more popular implementation of deep linking for Flash and Flex is with SWFAddress. It is a lightweight javascript library that provides deep linking features when used with SWFObject. Visit www.asual.com/swfaddress/ to know more about SWFAddress . The resources section at www.asual.com/swfaddress/resources/ together with samples and documentation provide a wealth of information on how to implement deep linking with SWFAddress.

URLKit is another implementation of deep linking for Flex. It was written by Joe Berkovitz and Todd Rein of Adobe. David Tucker explains the functioning of URLKit in detail with this excellent article: Advanced Flex Deep Linking with URLKit. You can also find documentation for URLKit at www.davidtucker.net/docs/urlkit/ .

No comments:

Post a Comment