views:

2741

answers:

4

How do I determine the URL of the current page from within Flex?

+2  A: 

I searched and came up with this url. I've honestly never used Flex, but it looks like the important part of that document is this:

private function showURLDetails(e:BrowserChangeEvent):void {
  var url:String = browserManager.url;
  baseURL = browserManager.base;
  fragment = browserManager.fragment;                
  previousURL = e.lastURL;                

  fullURL = mx.utils.URLUtil.getFullURL(url, url);
  port = mx.utils.URLUtil.getPort(url);
  protocol = mx.utils.URLUtil.getProtocol(url);
  serverName = mx.utils.URLUtil.getServerName(url);
  isSecure = mx.utils.URLUtil.isHttpsURL(url);        
}

Either way, good luck! :)

Eric
+3  A: 

Hello,

Using ExternalInterface (flash.external.ExternalInterface), you can execute Javascript in the browser. Knowing this, you can call

ExternalInterface.call("window.location.href.toString");

to get the current URL (note that this will be the page url and not the .swf url).

hth

Koen

Koen Weyn
+5  A: 

From the Application:

var myUrl:String = Application.application.url;
jsight
A: 

From the Application, use: this.loaderInfo.loaderURL

to break it apart and use parts of it do:

var splitURL:Array = this.loaderInfo.loaderURL.split('/');
var baseURL:String = "http://"+splitURL[2];
shi11i