Tuesday, March 2, 2010

Execute Javascript in AS3 without it being on the host page...

One can have internal javascript functionality from within their SWF. We are passing the JS function to the browser to execute it. For this to work on the most popular browsers the object tag in HTML must have "allowscriptaccess='always'" and the object tag must have an id attribute in HTML for IE to work. And of course Javascript must be enabled for the browser to interpet and execute the given script.

Example:
Get domain we are in

var hostDomain:String = String(ExternalInterface.call("function(){ return document.domain;}"));

This returns the domain that loaded our SWF. They could be loading it from your server but serving it on their domain.