views:

21

answers:

2

Hello people,
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

+1  A: 

Hi,

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.

Avi Tzurel
writing another JS means another dependency!! which is not desirable! I have foun out the problem now! but I don't know how to solve it! I have embedded the swf with SWFObject! and BrowwserManager doesnt work with SWFObject!!there is no error, simply the url returned by bbrowserManager is NULLL!
Ali Syed
You did not mention you are working with SWFObject?never mind.The solution is to comment out some code inside History.js and having it attached to the HTML file as well.here's the code you should comment out./*if (player == null || player.object == null) {player = document.getElementsByTagName(‘embed’)[0];}*/and this/*if (players.length == 0 || players[0].object == null) {var tmp = document.getElementsByTagName(‘embed’);players = tmp;}*/
Avi Tzurel
A: 

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.

Avi Tzurel
I don't find the second piece of code to comment it out! I just found the first snippet! but the second one is simply not there!
Ali Syed
could you look into it again??? btw I have upgraded to Flash Builder 4 (Flex 4)
Ali Syed