Flex & Tutorials 06 May 2008 12:23 pm
Flex Deep Linking
Flex let’s you build a kick ass UI every quickly. The Flash runtime creates a nice little sandbox so you don’t have to worry about tweaking your code for different browsers. The downside of this is that the Flash sandbox is completely opaque to the browser. If you have a Flex based photo album viewer, for example, and you want to show you friend a particular image in that album viewer. A regular user’s first instinct is to copy and send the URL, and we all know what’s going to happen next. Fortunately, deep linking in Flex is not difficult. This tutorial will show you how.
Flex 3 Deep Linking vs. SWFAddress
Deep linking is one the new features in Flex 3, but the technique has been used by Flash developers for quite a while. The most notable implementation is called SWFAddress.
So what’s the difference between the Flex 3 deep linking feature and SWFAddress? Not much. So why should you choose one over the over? Personally, I found the SWFAddress implementation to be much cleaner. Flex 3 deep linking is great if you never have to touch the HTML/JS templates, but that’s rarely the case once you start doing serious Flex development. This tutorial is going to focus on SWFAddress, but it should be conceptually applicable to Flex 3 builtin deep linking.
In the browser environment, every time a user changes the URL, the page is reloaded. The only exception is when you load a HTML page anchor. In the URL, the anchor starts with the “#” sign. The deep linking technique is based on manipulating the HTML anchor in the URL. For example, if you Flex application URL is http://myflexapp.com/index.html, a deep link would looking something like http://myflexapp.com/index.html#/param1=123¶m2=true.
To use SWFAddress deep linking in your application, you need go through the following steps,
- Clear out the html-template folder and replace it with SWFObject and SWFAddress templates. Copy the SWFAddress ActionScript files to your src directory.
- Handle URL change events
- The SWFAddress.onChange event is fired whenever the URL is changed in the address bar of your browser
- Create a private function which takes no parameters and return void. It would be the handler for your URL change event
- Attach the newly created function to SWFAddress.onChange during application initialization
- The new address string could be accessed via SWFAddress.getValue()
- Update the URL
- To change the deep linking URL, simply call SWFAddress.setValue and pass in the new address as the string parameter
- To pass multiple parameters into the URL encoding, you could either concatenate the parameters or use the URLUtil class on a collection object
- For a concrete example, take a look at the sample project attached to this post
What about URLKit?
When you are using SWFAddress, you are essentially given a getter, a setter, and an update event for the URL. You still have to construct code to interpret the parameters. This could get dangerous if you are trying to encode the state of multiple components into one URL. URLKit insulate you from directly accessing the URl string. Instead, it creates a rule based system which allows you to map variables to URL, group several variables together, and delegate URL handling to a sub component safely. URLKit is designed for Flex with full MXML support. I will not cover URLKit in detail in this post, but please let me know if you are interested in finding out more. I could write a tutorial for URLKit if there’s sufficient demand.
Need to bring your Flex project up to speed? Zee Yang is a freelance Flex developer with deep understanding of architecture and user experience. You can reach him at zee.yang@gmail.com.

on 07 May 2008 at 6:17 pm 1.stef said …
hey zee -
great talk! thanks again – a bientot – stef
on 07 May 2008 at 7:51 pm 2.Dylan DePass » Flex Deep Linking said …
[...] Flex Usergroup tonight Zee Yang gave a great presentation on Deep Linking in Flex. He also made a post about it in his blog which examines Deep Linking with SWFAddress. He explains it quite well and [...]
on 19 Jun 2008 at 10:50 pm 3.Hiew said …
I am interested in that tutorial for URLKit, specifically:
How to use URLKit with SWFAddress/SWFObject instead of the default Flex 3 BrowserManager HTML Template?
Explanation:
I prefer SWFAddress/SWFObject for a variety of reasons including cleaner HTML/JS and Google Analytics integration.
From documentation, it seems that URLKit is made for the Flex 3 BrowserManager. So, I am curious if there is a way to leverage it with SWFAddress/SWFObject.
on 24 Oct 2008 at 1:28 am 4.Fryck said …
Hi,
I’m really Interested for URLKit tutorial, and concret example, thanks !
Fabouney.
on 15 Dec 2008 at 11:39 am 5.Rich Tretola said …
URLKit is covered pretty well here:
http://www.insideria.com/2008/09/advanced-flex-deep-linking-wit-1.html
on 28 Jan 2009 at 7:53 pm 6.corey said …
Zee
thanks for the tutorial. I have notice though in your example and my example that the browser back button/fwd button doesnt work and the deep link , when copied n pasted , doesnt load the correct data. I ran into this same problem and was wondering if you found a way to fix it? thanks again!
Corey
on 27 Feb 2009 at 6:07 am 7.MechanisM said …
I’m usind URLKit always. And I think that its better then SWFAddress
on 31 May 2009 at 10:07 am 8.Jonathan Campos said …
Check out this blog post to ssee deep linking with seo: http://unitedmindset.com/jonbcampos/2009/01/27/deep-linking-seo-with-flex/
on 24 Jun 2009 at 9:27 am 9.Steven j steele said …
Hi Zee;
Hope you can help me or at least point me in the right direction.
I am designing on Flex Builder 3 Professional on a MAC OS X 10.5.7 (leopard), Adobe Flash 8 Professional;
testing OS include Windows XP SP3 box with no issues
when deployed to server.
For a look at what I want to do please visit my site at: stevenjsteele.com, click on the “Designer” button in the navigation bar at top, click on the watch flash video link in the center flash video designer panel.
As it stands now when I use a page button to click away from this panel’s viewstack the video continues to play.
What I want is to click on the “return to designer page” button and stop the swf from playing.
I am using a purchased ActionScript/javascript 2 FLV player component that uses an XML playlist to load FLV files into a SWFLoader control into a SWFObject.
Any help is appreciated.
Respectfully,
Steven
on 10 Dec 2009 at 8:34 am 10.brian said …
thanks for the flex deep sample code, very helpful !
on 08 Jan 2010 at 5:46 am 11.switcherdav said …
Hi, thanks for this exemple, but I found the same problem than Corey
Back et Forward buttons doesn’t work in your exemple
the ChangeEvent never Handled by Flex
mac os safari and FF 3