This is relatively simiple all you need to do is instansiate and access the BrowserManager object, from this object you can get all sorts of useful information about the URL that holds the FLEX object.
You will need to import the following classes.
import mx.utils.URLUtil;and the declare vars for the bits of the URL you want to get at
private var serverName:String;Then in your application.CreationComplete event function lets call it initApp() you need this
private var portName:int;
private var protocolName:String;
private function initApp():void
browserManager = BrowserManager.getInstance();
browserManager.init("", "Browser Window Title");
var url:String = browserManager.url;
serverName = mx.utils.URLUtil.getServerName(url);
portName = mx.utils.URLUtil.getPort(url);
protocolName = mx.utils.URLUtil.getProtocol(url);
You then have your current server url all nicely in vars and you do not need to hard code your URLs in the rest of the code. (you will need to make the vars [Bindable] if you want to use them in other objects!)
There are loads of other methods associated with the BrowserManager Class which you can find here.