Flex BrowserManager back button navigation vs -use-network=false
October 21, 2008
I haven’t posted yet about how I did the implementation of my final Master’s HCI project in Adobe Flex. In short, I had not worked with it before but I found it an incredible environment, very easy to pick up and do lots of fun stuff. I can also recommend this book that was a great learning resource, especially for someone like me who has the very basics nailed down but needed guidance with a bit more advanced stuff, e.g using custom components as ItemRenderers and what not.
Anyway, the DMD project posting will possibly be for another day. Today I wanted to post about something that I ran into, that apparently forces me to make an either-or decision about the features I want to use. The main point, as far as I can see is this:
When using -use-network=false to gain access to local content, you cannot use BrowserManager to provide browser history management and back/forward button navigation.
Here’s a bit longer version. I was doing a small application where I had several view states and wanted to use browser back and forward buttons so that the user could easily move around. Turns out doing this in Flex is really easy. First upon initialization, you register a few handlers:
browserManager = BrowserManager.getInstance();
parseURL is a function that gets called any time the URL changes – either the user entering it directly, or through your application. And then in your code, whenever the view changes, you just call this:
The text can be anything unique, as long as you can make sense of it yourself. And now back and forth navigation works and everything is happy.
Well, all was good so far, until it turned out that I needed to access some local content. (Specifically, load a local FLV file into a VideoDisplay component, because the whole thing would be running offline.) As far as I know, you just need to pass -use-network=false to Flex compiler options, and then you can work with local content. Basically network and local content are an either/or proposal, you can’t have both. Which is OK.
… except that the BrowserManager manages the browser state assuming it still is in the network. And when you try to set the fragment while -use-network is false, you will start to see ugly warnings like this:
Since I was producing something for executive stakeholders, it was not an option to pop up ugly stuff like this to them and force them to go through hoops to fiddle around with their settings.
At the end of the day, I needed to get this done quickly so I had no time to do further research. Since the prototype was tiny and the navigation was not complex, I could afford to just comment out all the BrowserManager stuff and not have any back/forward button state management. Is there a better way to do this (still manage browser state nicely while in no-network mode)? I don’t know. If anyone knows, let me know.