I'm trying to get current browser url. I have already tried with External Call, and it didn't work. And with loaderInfo.url I receive the current SWF url.
6 Answers
Give this a go:
import flash.external.ExternalInterface;
var url:String = ExternalInterface.call("window.location.href.toString");
if (url) textfield.text = url;
should do the trick.

- 306
- 4
- 10
-
funny thing, you can write javascript inside actionscript without the need of html. – atilkan Jun 04 '12 at 05:39
-
What does the toString do? Is that a function added by Flash? – Eddie Apr 18 '15 at 18:12
var url:String = loaderInfo.loaderURL;
seems to work too.

- 20,200
- 11
- 84
- 98

- 21
- 2
There are a couple of ways to solve this problem, however all of them involve the use of JavaScript to query the browser directly.
My preferred way to solve this problem would be to provide the URL via a flashVar property, direct from the embed code (personally, I would reccomend using SWFObject to make this easier); don't forget you will need to URL Encode it to avoid markup issues.
var flashvars = {
browserURL: escape(location.href)
};
swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0", "expressInstall.swf", flashvars);
Now you will be able to access the Browser URL via the loaderInfo object:
trace(stage.loaderInfo.parameters["browserURL"]);
note that this will only work if you have control of generated HTML for your SWF file - if users are going to be grabbing the SWF and writing their own embed HTML, it's not going to work.
If you don't have control of the flash embed HTML, then you will need to get flash to query the browser at runtime using the ExternalInterface class; other people have suggested the use of "window.location.href.toString" however this can prove problematic in IE6, I find the following works reliably across all browsers
const browserURL : String = ExternalInterface.call("eval", "window.location.href");
Note that in order for this to work, you will need to grant JavaScript access to your Flash movie, this is done, again, via the HTML embed code and the allowScriptAccess param

- 6,119
- 2
- 26
- 28
I would try passing the required info in as a flashvar. Not the best out of the box solution I know, but it will work.

- 2,809
- 4
- 29
- 39
-
The only problem with this technique is Flash will break some urls apart into individual variables. This happens with GET URL's, ie: *.com?one=1&two=2. So keep that in mind! – Tyler Egeto Jan 25 '10 at 00:31
-
@TylerEgeto you can fix that by encoding the URL with HTML special chars – Tchakabam Feb 17 '14 at 15:10
i think its posible to use the external interface an do it with javascript window.location

- 15,444
- 11
- 59
- 88
I have been using flash for a long time and never noticed this one. It only gives the domain though for security. It does work through loaded swfs as well. Not sure about iframes.
Security.pageDomain

- 1,428
- 14
- 24