SWF_Protector AS2 class

Description:

Provides several ways to protect SWF files that can be used in any combination:
  1. Good old "checking the _url" protection
  2. Loading external text file (url-encoded) from your server. Recommended for "smart" clients. Remember about crossdomain.xml file !
  3. Expire by time (like trial version)
  4. Bytecode. If you have some good __bytecode__() at hand that will (as you think) crash decompilers, place it in a frame in some clip in library and attach at runtime.

If the violation is detected, you can
  1. Unload _root leaving the screen blank
  2. Show an alert message telling them ... something
  3. Call your own action after checking the isViolated flag property (see below for example).

This code-only version is intended for programmers.

Arguments for constructor:

  1. url_check An object that specifies parameters of "checking the _url" protection:
    • _use - Boolean, use this protection or not
    • goodUrl - String, should be present in any valid URL (_root._url)
    • alert - String, message to show if URL is not valid
  2. load_file An object that specifies parameters of "external text file" protection:
    • _use - Boolean, use this protection or not
    • fileUrl - String, an URL of file to load
    • keyName - String, key name in the above file
    • keyValue - String, key value in the above file
    • maxTime - Number, max time to load file in seconds
    • alert - String, message to show if file is not loaded or key is not valid
  3. time_block An object that specifies parameters of "expire by time" protection:
    • _use - Boolean, use this protection or not
    • msGetExpired - Number, timestamp to expire. For example:
      new Date(2007,2,7,8,0,0).getTime()
    • alert - String, message to show if time is expired
  4. byte_code An object that specifies parameters of "bytecode" protection:
    • _use - Boolean, use this protection or not
    • linkage - String, linkage ID of a clip in the library.
  5. options An object that specifies some other parameters
    • _use - Boolean, use options or not
    • doUnload - Boolean, unloads _root if true.
    • showAlert - Boolean, will show alert message if true
    • alert - Object, properties of alert box:
      • alert.linkage - String, linkage ID of a clip in the library.
      • alert.textName - String, textfield inside this clip
        // both alert.linkage and alert.textName are required to attach a custom clip for alert box
      • alert.posX - Number, X position of alert box
      • alert.posY - Number, Y position of alert box
      • alert.background - Boolean, show bg for dynamically created text field or not. Same as TextField.background
      • alert.backgroundColor - Same as TextField.backgroundColor
      • alert.textColor - Same as TextField.textColor
      • alert.border - Same as TextField.border
      • alert.borderColor - Same as TextField.borderColor
      • alert.multiline - Same as TextField.multiline
      • alert.tFormat - TextFormat to apply to dynamically created text field

Usage:

To use this class, you must do the following:
  1. Import it using "import" statement
  2. Prepare arguments for constructor
  3. Call the constructor

Code Example
	//================ Example =====================
	import com.gousable.SWF_Protector ;
	//
	var url_check:Object = {};
	url_check._use = true;
	url_check.goodUrl = "http://localhost/123";
	url_check.alert = "Sorry, this site should NOT be shown here.";
	//	
	var load_file:Object =  {};
	load_file._use = true;
	load_file.fileUrl = "http://localhost/123/123.txt";
	load_file.keyName = "my_check";
	load_file.keyValue = "123QWERTY";
	load_file.maxTime = 3; // max time to load file in seconds
	load_file.alert = "Sorry, this site should NOT be shown here.";
	//	
	var time_block:Object = {};
	time_block._use = true;
	time_block.msGetExpired = ( new Date(2007,2,7,8,0,0).getTime() ) ; // 
	time_block.alert = "\nSorry, time limit for this site has expired.\n ";
	//	
	var byte_code:Object =  {};
	byte_code._use = true;
	byte_code.linkage = "swf_protector_bytecode";	
	//		
	var options:Object =  {};
	options._use = true;
	options.doUnload = false;
	options.showAlert = true;
	options.alert = {};
	//options.alert.linkage = "swf_protector_alert";
	options.alert.textName = "alert_txt";
	options.alert.posX = 100;
	options.alert.posY = 100;
	//
	options.alert.background = true;
	options.alert.backgroundColor = 0xeeeeff;
	options.alert.textColor = 0xcc6666;
	options.alert.border = true;
	options.alert.borderColor = 0xccffcc;
	options.alert.tFormat = new TextFormat();
		options.alert.tFormat.font = "Courier New";
		options.alert.tFormat.leftMargin = options.alert.tFormat.rightMargin = 20;
	//
	// now call the constructor
	_root.swf_protector = new SWF_Protector(url_check, load_file, time_block, byte_code, options);	
	//
	var timer1:Number = setInterval(this, "checkProtection", 5000);
	function checkProtection(Void):Void{	
		clearInterval(timer1);
		// check if protection is violated
		if(_root.swf_protector.isViolated){
			_root.debug_txt.text = "\n SWF PROTECTION VIOLATED";		
		}else{
			_root.debug_txt.text = "\n SWF PROTECTION :  OK";
		}
	}
	// =============== end of example ======================

Notes:

The SWF_Protector object has a flag property, isViolated, that can be checked if you prefer to set your own actions.
See setInterval and checkProtection function above - it shows a message in some special text field.

Download

You can download a MXP package or ZIP.
Also, see SWF_Protector at Google Code
 
 
Text2Curve screenshot
Text2Curve
Text2Curve Flash component allows you to place text along one of pre-defined curves.

Now you can use these effects in Flash IDE or at runtime.
Easy to configure.

See also: