Skip to content

Instantly share code, notes, and snippets.

@blt04
Created January 13, 2012 18:01
Show Gist options
  • Save blt04/1607809 to your computer and use it in GitHub Desktop.
Save blt04/1607809 to your computer and use it in GitHub Desktop.
Security.allowDomain sub-domain support
// Allow thinkwell.com and thinkwell.com subdomains
// The current domain is automatically added. The AllowDomain flash
// var can be used to add an additional domain.
private function setAllowDomains():void{
// Only apply allowdomain security settings to thinkwell.com and subdomains
var pattern:RegExp = /^(.*\.)?thinkwell\.com$/
var allowDomains:Array = new Array();
// Try to add the current domain
try {
var url:String = ExternalInterface.call("window.location.href.toString");
var host:String = URLUtil.getServerName(url);
if (host && pattern.test(host)) {
allowDomains.push(host);
}
} catch(e:Error) {}
// If the the AllowDomain flash var exists, add it to the allowedDomains
// list as well
if (parameters['AllowDomain'] && pattern.test(parameters['AllowDomain'])) {
allowDomains.push(parameters['AllowDomain']);
}
if (allowDomains.length > 0) {
Security.allowDomain.apply(Security, allowDomains);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment