05 January 2010

Sitelocking an Actionscript 3 Flash Movie (SWF)

Sometimes you need to make your Flash movie (or game) to work only on selected domains. Sometimes you may want to blacklist some domains so they can’t display your Flash content.
This is called sitelocking, and means you lock a movie to a specific site.

Site locking is important if you want to keep your game locked to your site, or you’re posting it on a site but don’t want it stolen from that site. Remember to remove the site locking code when you feel like distributing the game around.

It’s also best to encrypt your swf, since if people can decompile it, using any number of swf decompilers around, then they can easily remove your site locking.

Let’s see how can you sitelock a Flash file.

 
var lockURL:String = "kornesh92.blogspot.com";
var lock:Boolean = true;

var urlString:String = stage.loaderInfo.url;
var urlParts:Array = urlString.split("://");
var domain:Array = urlParts[1].split("/");

if(lockURL!= domain[0]){
 trace("Access Denied. You dont have permission to host this swf on your site.");
}

site lock to a set of possible urls instead of only one? Well, you’d create an array of url strings and then check against that. Like this:

 
var lockURL:Array=["localhost","www.site2.com","www.site3.com"];
var lock:Boolean=true;
var urlString:String=stage.loaderInfo.url;
var urlParts:Array=urlString.split("://");
var domain:Array=urlParts[1].split("/");

for (var i:uint = 0; i < lockURL.length; i++) {
 if (lockURL[i]==domain[0]) {
  lock=false;
 }
}
if (lock) {
 trace("Access Denied. You dont have permission to host this swf on your site.");
}

1 comment:

  1. So how do you break Site locks and enryptions, like Nitrome games?

    ReplyDelete