how to find URL of the page where the Flash file is embedded

1.5k Views Asked by At

I am writing a Flash app in Flex Builder 3. I have a problem. I need the URL of the place where the Flash app has been embedded.

mx.core.Application.application.url

This gives me the address of the original swf file, but I actually need the URL of the HTML file where this SWF has been embedded. is there a way ??? thanks! Ali

2

There are 2 best solutions below

2
On

You have 2 options. in flex:

private function initApp():void {
        browserManager = BrowserManager.getInstance();
        browserManager.addEventListener(BrowserChangeEvent.URL_CHANGE, showURLDetails);            
        browserManager.init("", "Welcome!");            
    }

and the listener

        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);        
    }

That code works both on the server and on Local host.

if that does not work for you (upload the error here first) but you can also create a JS function that will return the URL and have flex call this function.

1
On

my comment is unreadable so here it is as an answer.

The code inside SWFObject makes flash act alittle wacky when it comes to the browser manager. the solution is inside history.js (first attach it to the HTML if you didn't)

Then, comment out these lines of code.

if (players.length == 0 || players[0].object == null) {
var tmp = document.getElementsByTagName(‘embed’);
players = tmp;
}

And this one

if (player == null || player.object == null) {
    player = document.getElementsByTagName(‘embed’)[0];
    }

This should solve your problem.