Together with Todd Rein of Adobe Systems, I’ve been working for some time on a Flex library called UrlKit that helps with the thorny problem of coupling a browser’s URL-based navigation to the behavior of a Flex application. It’s finally ready to release in a provisional form. You can get it from Google Code.
What’s so cool about UrlKit?
- A new UrlKit URL appears in the browser’s location bar whenever your application state changes. Likewise, whenever the browser navigates to a UrlKit URL, it is parsed and the application receives a new state without being reloaded. Bookmarks and Back/Forward are thus supported seamlessly.
- You get to define what “state” means. Absolutely any aspect of your Flex application can be coupled to the browser’s URL, not just properties of UI components.
- Your URL syntax is as transparent, readable and maintainable as you like, e.g. http://example.com/myApp.html#/search;keyword=cameras;productId=123. Unlike the built-in Flex history mechanism, you can completely control the URL syntax and what goes into it.
To see it in action, try the sample application.
Here’s an MXML snippet showing what it’s like to set up a URL/state mapping like the example given above, binding the different URL pieces to various bindable variables in your application:
<url:UrlRuleSet> <url:UrlValueRule urlFormat="/*" sourceValue="tabName"/> <url:UrlValueRule urlFormat=";keyword=*" sourceValue="searchKeyword"/> <url:UrlValueRule urlFormat=";productId=*" sourceValue="productId"/> </url:UrlRuleSet>
Todd and I think this is pretty fun and powerful stuff, and we’re using it at Allurent in some of our applications. Looking forward, this will be an important tool in integrating conventional HTML-based search engines with Flex applications.
Final note: it’s still in an early stage, so expect a few rough edges! There’s been no exhaustive browser testing and there are some known issues with Safari.