PDA

View Full Version : getCodeBase() in ActionScript


eproulx
12-14-2008, 08:09 PM
I'm porting a Java Applet to ActionScript. I need to get the current browser's URL. In Java I simply do Applet.getCodeBase() which returns the address of the page hosting the applet.

What's the equivalent in ActionScript?

I tried to google it but I'm getting too many results because these keywords url, address, page, etc, are too general.

Thanks,
Emmanuel

wvxvw
12-14-2008, 08:20 PM
This is possible only if HTML page allows Flash app to interact with it. This is the default behavior in situation when SWF and HTML both originate from the same domain. But if they are not, you'll have to specify it in the allowScriptAccess tag of the HTML wrapper.
What you'll have to do is something like:
ExternalInterface.call("function(){return document.location.url;}");
To get the URL of the SWF, or image loadeded into Flash player you'll have to look at LoaderInfo.url (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html#url)