Looking for a quick and easy way to sitelock your flash game in Actionscript 2? In this post I’ll show you how to sitelock your game using a simple bit of AS2 code.

Sitelocking is the process of making a version of your game that can only be played on the specific sites that are put into your sitelocking code. It essentially locks your game to those sites, making it so that they cannot spread to other sites on the internet. It can be useful when you want to make custom versions of your games for different sites, also known as exclusive licenses. Or it can be used to make sure your game in beta isn’t spread across the web, lowering your chances of getting a sponsorship.

Now that you know what the sitelocking process is, it’s time to learn the how to sitelock your game. The first thing you’ll want to do is set up the movieclip that will be shown when your game is played on a site that you don’t want it to be on. Here’s how to do it:

1. Open up flash and hit CTRL+F8. This will bring up the Create New Symbol box.

2. Name your symbol however you like; I’ll be naming mine siteLock. Make sure the Movie Clip option is selected and hit Ok.

3. Now create the image you want to appear when your game is on a site you don’t want it to be on. Make sure this image has the same dimensions as your game.

4. Now drag the image you just made onto your stage, and off to the side of the stage (so it would be off-screen when people play your game on a good site).

5. Give it the instance name of siteLock.

Now that you have your siteLock image set up, it’s time to add the code to your game. But before you do that, you’ll need to learn how to disable the right click menu, so players can’t just click past your sitelock screen.

Once you’ve disabled flash’s right click menu options, it’s time to add the code to your game. Here’s the actionscript 2 you’ll need to sitelock your game:

var urlString:String = _root._url//create a variable with the url of the website you are on
if(urlString.indexOf("freelanceflashgames.com") == -1){//if the url does not contain freelanceflashgames.com in it...
siteLock._x=300;//show the sitelock image in the center of the screen.
}//end code

Note: You may have to edit the _x value a little to get your image to be in the center of the screen. If you find your image is too high up or too far down on the screen, try moving it up or down on the stage.

Now what if you want to lock your game to more than one site? Easy, just put this actionscript in:

var urlString:String = _root._url//create a variable with the url of the website you are on
if(urlString.indexOf("freelanceflashgames.com" || "flashgamelicense.com") == -1){//if the url does not contain freelanceflashgames.com or flashgamelicense.com in it...
siteLock._x=300;//show the sitelock image in the center of the screen.
}//end code

That’s it for sitelocking. What this code does is check to see if the url contains the phrase you put inbetween the quotation marks. If it doesn’t, then the sitelock image is shown on the screen. The disabled right click menu we created earlier keeps the player from just right clicking their way past the sitelock screen, making sure that your game only goes on the sites you want it to be on.

Related posts:

  1. How to Sitelock a Game
  2. Tutorial to Stop Cheaters in a Maze Game using AS2
  3. How to Make a Clock in Flash using Actionscript