import flash.external.ExternalInterface;
var pageURL:String = ExternalInterface.call('window.location.href.toString');
The above code seems to work on Firefox, but when I try it with Chrome or IE it doesn’t work (it causes an Error and stops the swf’s execution).
Any hint?
ExternalInterfaceworks in recent versions of all major browsers. The first thing you should do is wrap that call in a check to see if it is currently available:The problem with Chrome and IE may be the call to window.location.href. Your best bet is to put this into a JS function, and then call that function from AS, like so:
Also, make sure the function you are trying to call is already present in the DOM before you try to call it – if you add your SWF before you add the script, and make the call to
ExternalInterfaceimmediately, then it will fail becausereportHrefdoesn’t exist yet.And, finally, it’s possible that a call from within the SWF to the
window.locationobject might fail due to sandboxing, which won’t be the case if you make the call from a JS funciton in the page.The docs on
ExternalInterfaceare pretty comprehensive, with good examples:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html