How to: determine if SWF is running in same browser domain as it was loaded from

This may sound like a strange request, but I need to be able to determine:

  1. What browser domain the current swf is executing in (that is, the page that hosts the swf is displayed in a browser, what is the domain of the page)?

  2. What server domain the SWF was loaded from (ie, what the URL domain was for the SWF)?

I believe both of these I can get via javascript and ugly workarounds and pass them in, but what I need is actually to get these values (at least #2) from inside the SWF without relying on the javascript in the hosting page.

Specifically, what I’m trying to determine is if the SWF is executing in a page from the same domain as it itself was hosted/loaded from. I want to fork on this test and create different behavior for a SWF if it’s “hot-linked” (that is, loaded onto a page on a different domain from where I host it).

I’ve looked into flash.system.SecurityDomain and ApplicationDomain… both these have properties called ‘currentDomain’ which would seem to be the value i’m looking for (for #2), however this object is a static variable that I can’t seem to get any information out of or transform into any kind of useful string that I can look at it’s value and test with it.

The only info I’ve found on either of those two classes all relates to passing them to LoaderContext and such, when you are loading external resources.

I do not want to load anything, I just want to determine how and where the SWF is executing.

please help!?

trace(loaderInfo.loaderURL); // Returns the path of your swf

You can specify where to load your data from using variables based on domain; example if you were at http://www.myserver.com/myswf.swf

var myServer:String = http://www.myserver.com

if (loaderInfo.loaderURL.indexOf(myServer)){
// if the file is located at www.myserver.com do something
}else{

//do something else
}

Hope this helps.

thanks dualpixel, I never would have thought to look there for the URL of the current executing SWF. that solves #2 perfectly inside the actionscript!

What about #1, is there a way to find out what browser domain the flash is executing in, without having to rely on javascript detecting and pushing that data into the SWF?

also, I found that creating a “LocalConnection” object and inspecting it’s “domain” property actually gives me exactly and only the domain name, not the full URL, so that’s closer to what I want.

I’m still struggling to see if SWF can find out what domain is in the browser bar of the page it’s executing in without relying on javascript.

anyone?

FWIW, I’m right now using: var pageurl:String = ExternalInterface.call(“window.location.href.toString”);

That gives me the URL that the window/page is on, in contrast to the URL that the SWF was loaded on.

However, if anyone can find a way to do this totally in actionscript and not rely on the javascript or HTML to determine it, it would be much appreciated.