Using Flex 3’s Deep Linking Features in Flex 2
December 12, 2007 on 5:26 am | In Flex, Programming |If you don’t already know, Flex 3’s deep linking support is a tremendous boon to the RIA developer, insulating our lot from having to worry about the whole sorry, shoddy business of communicating little strings between our application and the fragment chunk of the browser’s location URL. Applications that have some notion of navigational state benefit greatly from using this feature: their state (as embodied in such a URL) becomes automatically hooked up to the Back/Forward buttons, becomes bookmarkable, and of course becomes exchangeable via the usual Web means with any other user of the same application.
For those of us who have real products that need to be released on a schedule independent of Adobe’s corporate whims, however, Flex 3 isn’t necessarily a good option. Where does that leave the would-be deep linker? One of the few options for Flex 2 users has been the UrlKit library written by Todd Rein and yours truly, which provides deep-linking support in Flex 2. (In Flex 3, UrlKit uses the built-in deep linking mechanism.) Unfortunately, in Flex 2 the deep linking support in UrlKit is not equally good for all browsers. UrlKit supports FireFox, IE6 and Safari pretty well, but I’ve never had the time to catch up with IE7, and the prospects of my keeping up with the dirty little world of browser compatibility have been — and remain — dim. In contrast, Adobe is a big company with lots of smart QA people and a business motive to toil in the compatibility trenches.
Now, something not generally known is that the Flex 3 deep linking support is derived directly from the UrlKit code (and, yes, they had the authors’ permission!). As such, it has virtually no dependencies on the rest of Flex 3 — not surprising, since Todd and I built it for Flex 2. So it occurred to me recently that it should be possible to port the Flex 3 BrowserManager class and accompanying Javascript back into Flex 2, where it would probably simply compile and work out of the box. And the good news is: it does! (Actually that is a slight lie: I did have to comment out a single line of code, and add a one-line magic incantation to my application startup. But that’s not too bad.)
This means that Flex 2 developers (and UrlKit itself) can now take advantage of the Flex 3 BrowserManager subsystem in its entirety. Furthermore, I am aiming to provide a new revision of UrlKit shortly that incorporates this approach for its Flex 2 deep-linking support.
I cannot legally redistribute the slightly modified Flex 3 source that works in Flex 2, but here’s how to do it yourself:
- create a new Flex Library project based on the Flex 2.0.1 SDK
- copy the following files into it from the Flex 3 SDK source:
- mx/core/Version.as (note: this is included by the other files, but not compiled itself)
mx/events/BrowserChangeEvent.as
mx/managers/IBrowserManager.as
mx/managers/BrowserManager.as
mx/managers/BrowserManagerImpl.as - comment out the line in
BrowserManagerImpl.init()which sets thehistoryManagementEnabledflag — this does not exist in Flex 2. - compile the above files (excluding Version.as) into a SWC
- in your Flex 2 application, drop in an HTML template generated by Flex Builder 3 for a Flex 3 deep-linking app. This template will include a
history/subdirectory with JavaScript and CSS files in it, and the HTML page loading the app will refer to those files. - Add the following line to your application startup, prior to calling
BrowserManager.getInstance()Singleton.registerClass("mx.managers::IBrowserManager", Class(getDefinitionByName("mx.managers::BrowserManagerImpl")));
I have some more testing to do, but a development version of UrlKit that I just compiled with this approach seems to work well at first blush.
Happy linking!
3 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Entries and comments feeds.
Valid XHTML and CSS.
All content copyright (c) 2006-2007 Joseph Berkovitz. All Rights Reserved.
Awesome. Was just thinking yesterday how nice it would be to use Flex 3 deeplinking for a Flex 2 project I’m working on. Also great talk at flex camp boston, that color matching feature was pretty sweet!
Comment by Dan — December 12, 2007 #
Very cool !!
Thanks
Comment by Mrinal Wadhwa — December 12, 2007 #
Came across your post while perusing Google.com for deep-linking with Flex3. I just may try this with my Flex builder 2
Comment by Otuyelu — January 29, 2008 #