The Junk In My Trunk

Flex Browser Manager, URLUtils, and modules.

by Tony on Jan.09, 2009, under Flex

My recent experience with the Flex Browser Manager and the URLUtils class and modules has been a long and anoying one… but I think I almost have it!

I know now that part of my troubles is the way my application is written - not poorly, but it makes passing url variables to modules complex as they load at different times.

Here is what happens:
The main application loads and parses the url from the browser. It then deals with any passed variables. At the same time, it gets a list of modules to load from the back end, and then loads them. Unfortunately, this process takes about 500ms to 1000ms longer - so I have all of this data, and no modules loaded to pass it to.

That in it self, is not a problem. I can just cache the data. But my data cache waits for the modules to load, then then sends the data. Well - after the modules load, then they load their own data from each other. So, by the time they are actually ready for the url variables, it’s already been sent and failed because they were not ready when it was sent.

I don’t have an easy solution for this - I could rewrite lots of code to make it work differently, but I think that this is a poor reason to rewrite the code. I can’t think of many other reasons to rewrite the code this way, so I think that it might be easier to find a hack for the url variables instead of rewritting hundreds of lines of code to work with them.

So, my solution has been to not parse the url when the main application starts. Instead, I wait for the modules to load, and then I parse the url. This way, I only have to cache the data for a few seconds at most, and all is well.

Also, since I have many modules that might or might not be loaded, each with their own information that needs to be in the url, I needed a uniform way to put these variables in the url. So I came up with the following standard:

http://www.site.com/application.html#ModuleName1=(data.data.data);ModuleName2=(data.data.data);

I use the ModuleName=(); part to seperate out each modules data. The URLUtils class has a String to Object function (strToObject I think) that can easily parse a string into an object. It uses the ; character by default, so that seemed good enough to me to use. So it would parse the url above into the following object:

{”ModuleName1″:”(data.data.data)”, “ModuleName2″:”(data.data.data)”}

So, then I wrote a simple function to parse that object into an array that I pass to each module. It parses the string “(data.data.data)” and puts each data chunk into an array element. So this array is what gets passed to each module:

["data", "data", "data"]

The functions in my main application take it no further then thata. Each data chunk can be ANY url encoded characters. (Although I haven’t written the code to url encode and decode them yet, I still have to do that.) So it is up to the modules to specify a data format that they can handle for their data chunks. Since I am the only developer, I decided to make all of my modules parse the following data chunk standard:

[adata, adata, bdata, bdata, bdata, cdata]

What that means is each data chunk starts with a single letter. This is to so that I can simply write a switch block to look for the first letter and deal with the data that way. As I said above, this isn’t needed, and each module can do whatever it wants - but this is the way I do it just to make it easier for my self.

So, here is an real example of a url that my application uses:

http://www.site.com/mainapplication.html#SearchTools=(a16.a17.o17);MediaPlayer=(s16.t3);

Here is what that url means:

The SearchTools module gets three data chunks - a16, a17, and 017. This tells it to set three search categories - two add categories and one only category. I’ll explain that is a later post.

The MediaPlayer module gets two data chunks - s16 and t3. This tells it to load song 16 and track 3.

I could also pass the MainApplication data in this same format.

So there you have it - a somewhat simple url format that an application can use to send data to it’s modules.

No comments for this entry yet...

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

The best places on the internet:

My other content and some friends...

Archives

All entries, chronologically...