Let's say I had a flex application (Web, not Air), that was meant for Mass Distribution, to be included like a plug-in of sorts, at various websites. Is there any way for a particular instance of the SWF to detect it's own URL while it's running? If so, can you point me in the right direction of which ActionScript command I might google for more info?
+5
A:
loaderInfo.loaderURL gives you the SWF url in your document class.
You can also do this but it's dependent on allowScriptAccess in the embed code:
if(ExternalInterface.available) // import flash.external.ExternalInterface;
{
try
{
url = String(ExternalInterface.call("window.location.href.toString"));
}
catch(s:Error)
{
url = loaderInfo.loaderURL;
}
}
That will give you the actual page url if it's able to. In my experience with widely distributed games in Flash you can't really rely on allowScriptAccess being set to enable this method. Your miles may vary.
Ben
2010-08-19 03:49:26
+1
A:
Accessing the SWF URL and accessing the URL of the page enclosing the SWF are two very different things.
Application.url will give you the SWFs URL. The Flex 4 Application has the same property.
There is no guaranteed way to get the URL of the loading HTML page, but you can use ExternalInterface to do so on some situations. ( @Ben's answer is spot on there ).
www.Flextras.com
2010-08-19 10:40:40