As I was digging around the allowNetworking setting and how the SWF can determine it at runtime, I decided to go deeper and catch other types of embedding restrictions, like the allowScriptAccess parameter. I've seen sites that block outgoing links of certain flash files - in most cases flash games are prevented to access the web, resulting in negative effect over their authors - the game developers.
Here are the allowed settings for both HTML parameters:
allowScriptAccess:["always" / "sameDomain" / "never"] allowNetworking:["all" / "internal" / "none"]
The following useful script determines any of the mentioned restrictions:
if (Capabilities.playerType != "External" &&
Capabilities.playerType != "StandAlone"){ var url:String; try{ navigateToURL(new URLRequest(null)); } catch (err:*){ if(err is SecurityError){ trace("SECURITY ERROR::allowNetworking is disabled!"); throw new Error("ERROR::allowNetworking is disabled!\n"+err); } else { trace("SECURITY::allowNetworking is OK!"); } } try{ if (ExternalInterface.available){ url = ExternalInterface.call("window.location.href.toString"); } else { url = _stage.loaderInfo.loaderURL; } trace("SECURITY::allowScriptAccess is OK!"); } catch(err:*){ if(err is SecurityError){ trace("SECURITY::allowScriptAccess is disabled!"); } else { trace("SECURITY::Unknown Error!",err); } }
The script first checks if it is running in a browser online with Capabilities.playerType, then tries a null URLRequest to determine the allowNetworking setting.
If allowNetworking is set to "all" the compiler will throw a TypeError, otherwise with "internal" or "none" setting there will be a SecurityError.
Next allowScriptAccess is verified using ExternalInterface in attempt to retrieve the current URL with the javascript call "window.location.href.toString".
Again a SecurityError will differentiate "always" from "sameDomain" and "never".
Finally an "url" var is available for further evaluation, domain check or tracking purpose.
For convenience, I'll include the import statements as well:
import flash.net.URLRequest; import flash.net.navigateToURL; import flash.system.Capabilities; import flash.external.ExternalInterface;(It's a hard quest to import classes manually after a copied snippet, isn't it :)
Let me know if you have issues with the above code. Thanks.