Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Current Browser URL - ActionScript 3

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.

like image 578
lfduvidas Avatar asked Jan 24 '10 17:01

lfduvidas


4 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.

like image 53
Shrill Avatar answered Nov 02 '22 19:11

Shrill


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

like image 31
JonnyReeves Avatar answered Nov 02 '22 20:11

JonnyReeves


var url:String = loaderInfo.loaderURL;

seems to work too.

like image 32
William Avatar answered Nov 02 '22 20:11

William


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.

Flash: FlashVars in AS3

like image 1
nokturnal Avatar answered Nov 02 '22 20:11

nokturnal