Subscribe to Tutorial Feed

Flash and PHP Bible

The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.

The Flash and PHP Bible has a forum for quick support.

Scriptplayground » tutorials » as » Securing your Flash Work

Securing your Flash Work

A simple method used to protect your Flash work. Note this is not 100% secure as it still suffers from the ability to rip apart a movie.

First off we use a simple actionscript to test the location of the movie.

var good_url:String = "";
var current_path:String = _url;
if (current_path.indexOf(good_url) == -1) {
    // bad location

The problem with this code is the thief could simply add a query string to the url and the check will be valid. Not exactly the result we are looking for, so on to a more in depth process of validating the location.

This other "better" option will be in a function that will return a true/false result on validation. We do this so the code can easily be reused over and over again.

function check_location() {
	// The good location
	var good_url:String = "";
	// we add the correct domain as a query string, but notice it doesn't check out
	var current_path:String = _url + "/chocolate/chip/type?";
	// now we pull apart the location to end up with a domain name piece
	var domain = current_path.substring(current_path.indexOf('http://') + 7).split('/');
	if(domain[0].indexOf(good_url) == -1) {
	    // bad location
		return false;
	return true;

if(check_location()) {
	trace("running on a good location");

As you can see this is a tougher check, but still suffers from the same limitation and that is Flash can be decompiled.

Well thats about it, now you should have a better understanding of how this all works.

Follow Scriptplayground on Twitter (@scriptplay)

Comments: Securing your Flash Work

 Vinny  Thu Aug 10, 2006 5:57 am  
 michael095  Thu Apr 7, 2011 12:42 pm  

I decided to describe the following case, cause You helped me in the other tutorial, and offered help in the future. I have built many websites which are based on Flash / AS3, and during that work i met few obstacles that some times still come back to me. One of them is connected with tutorial in the top. I have already been searching for answers on many websites, but with no result, maybe just because it's impossible without php / cookies / etc.. Lets get started:

I need to define (from ActionSctipt console) the expire date of my *.swf movie file. I already wrote the simple code which works - i define the date zero (year / month / day etc.), and after i cross this date, the movie goes to the frame with information about its expiration.

Take a look:

var Zero:Date = new Date(2011, 5, 1, 0, 0);
var Today:Date = new Date();

if (Today > Zero) {
else gotoAndPlay("start");

I know that this amateur example of "protection" is easy to brake in dozens of ways - for example by manipulating the system date or using the flash decompilers.

So... I've wonder if You know the solution for at least one of these concepts which (in my opinion) should solve the problem:

1st concept) - modifying the code that in result will be resistant for system's clock manipulation, but without playing with cookies ;), cause if somebody just know what this is, then that will be the first he will check.

2nd concept) - the code is not responsible for taking care about the Date Zero - but for the number of views. For example - the future client watches my project 10 times, and then he'd be unable to play it again, or the movie automatically deletes itself from a hard drive. The condition is - this solution must work even locally.

3rd concept) - how would the code look like which reads the Date Zero from a file? for example the *.txt file which is on the server or hard drive that the client has access to?, and if he cuts off the internet access in order to let the movie read the date from the file, then it also should expire.

Thank You very much.
 michael095  Thu Apr 7, 2011 12:47 pm  
*..the client has NO access to, and if he cuts off the internet access so that the movie file would be unable to read the data from a file, then the movie should also expire.
 mkeefe  Tue Apr 12, 2011 11:16 am  
@michael095 - Due to the fact that system time can be altered I opt for the remote solution. What I do is place a file on my own development server, load that file at the start of the app and if it exists the clients project functions. However if the file is missing or has a warning message than that is displayed. I keep the message professional but direct, they of course know why its happening.. and normally rectify the situation immediately.

Hope that helps.
Add a comment
The ability to add new comments has been disabled in this archived version.

Main | Tutorials | Articles