Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get URL of current page from Flex 3?

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

like image 923
jsight Avatar asked Sep 15 '09 04:09

jsight


2 Answers

Let's be clear here.

1. If you want the URL of the loaded SWF file, then use one of these.

Inside your application:

this.url;

From anywhere else:

Application.application.url; // Flex 3
FlexGlobals.topLevelApplication.url; // Flex 4

If you are loading your SWF inside another SWF, then keep in mind that the code above will give different values. this.url will return the url of your SWF, where as Application.application.url will give the url of the parent/root SWF.

2. If you want to know the URL that is in the browser address bar, then use one of these.

BrowserManager method(Make sure you have the History.js included in your wrapper html for this to work):

var browser:IBrowserManager = BrowserManager.getInstance(); 
browser.init();
var browserUrl:String = browser.url; // full url in the browser
var baseUrl:String = browser.base; // the portion of the url before the "#"
var fragment:String = browser.fragment; // the portion of the url after the "#"

JavaScript method:

var browserUrl:String = ExternalInterface.call("eval", "window.location.href");

If you are parsing the url for parameters, don't forget about this useful function:

// parses a query string like "key=value&another=true" into an object
var params:Object = URLUtil.stringToObject(browserURL, "&");
like image 80
ccallendar Avatar answered Oct 06 '22 19:10

ccallendar


From the Application:

var myUrl:String = Application.application.url;
like image 34
jsight Avatar answered Oct 06 '22 18:10

jsight