There’s a difference between the URL your Flex application’s SWF file was loaded from and the URL your Flex application’s SWF file is actually running from.
The former is easy to retrieve via the read-only property Application.application.url.
The latter is (slightly) more complicated. Although Flex does not provide the built-in ability to determine the URL your Flex application is running from, our good friend JavaScript is happy to lend a helping hand.
Using ExternalInterface, you can call “window.location.href.toString” to retrieve the URL your Flex application is running from.
Although there are many different permutations to retrieve this URL using window.location, I prefer the above method because it also returns any query parameters passed into the URL.
I created a static class called JSUtil so I could quickly access this method in my code, the source of which you can view here.
Update: Code snippets I’ve posted using Private Paste are randomly disappearing, so if the above link no longer exists, here’s a backup.

No comments
Comments feed for this article