Tuesday, July 13, 2010

How to site lock a flash using Actionscript 3

There are many requests on site locking flash games and applications on the internet. There are many ways to do it, but I chose regular expressions for my code. Here it is:

var url:String=stage.loaderInfo.url;
var goodPattern:RegExp=/^(http:\/\/)(www\.)?newgrounds\.com/;
if (goodPattern.test(url)==true) {
 trace("This flash is hosted on newgrounds");
} else {
 trace("This flash is not hosted on newgrounds");
}

Basically, flash checks whether current url follows the scheme:
Beginning,"http:\\", "www." (may or may not be there), "newgrounds.com", the rest of the url.

This code is really easy to use and you can site lock your flash by simply changing the url in the script. However, the stealer could decompile the swf file and remove this piece of code, but even then, there's no 100% protection guarantee. Besides, 99% of flash stealers would just leave the flash alone when it won't let them put it on their site.

1 comment:

Anonymous said...

Hi nice post.
I wonder, if i want add multiple link, can i make like this? It seem doesn't work

var goodPattern:RegExp=/^[(http:\/\/)(https:\/\/)](www\.)?newgrounds\.com/;

Post a Comment