6

My flash app needs to know its own URL, so that it can load some (non-embedded) content using relative paths.

(I cannot hardcode the full paths because there will be multiple installs -- staging, production, etc. Nor can I use simple relative paths because there's one legacy install that uses a different relative path (ugh). And I cannot just embed the content, because it is shared. I need to get the full URL and then do some if statements with it.)

(Please note that the URL of the page into which the .SWF file is embedded will not work. The app is included in a CMS, so the page URLs can be quite different from the content URLs. I need the actual URL of the .SWF file.)

Can this be done programatically, or am I stuck with passing the URL as a parameter?

Eric
  • 11,392
  • 13
  • 57
  • 100

2 Answers2

11

In AS3, the URL of current swf file can be found via the LoaderInfo class instance. So in your main document class (or main stage frame script) this should give your the URL of your swf file:

this.loaderInfo.url

Every MovieClip has a loaderInfo member, that will give you its info.

LoaderInfo livedocs.

tehnomaag
  • 186
  • 5
  • This could work as a pretty great anti theft device, have the swf abort playing if the url doesn't match your own. – Karl Dec 29 '08 at 16:05
  • You *can* do that, but it's pretty easily circumvented if you decompile and replace that string so don't trust it too much ;) – grapefrukt Dec 30 '08 at 15:03
  • Hi I tried to implement code to trace out the URL here, but with no luck :( http://stackoverflow.com/questions/2059288/how-to-obtain-url-that-flash-movie-is-embedded-on – Leon Gaban Jan 13 '10 at 18:45
1

mx.managers.BrowserManager

Adobe Flex LiveDocs

Accessing information about the current URL

gregjor
  • 21,802
  • 1
  • 23
  • 16