In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

flash on 2010-5-5

Get Adobe Flash player
by kihon 05 May 2010
    Embed
/**
 * Copyright kihon ( http://wonderfl.net/user/kihon )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ce34
 */

package
{
	import com.bit101.components.NumericStepper;
	import com.bit101.components.PushButton;
	import com.bit101.components.TextArea;
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class Main extends Sprite
	{
		private var srcArea:TextArea;
		private var destArea:TextArea;
		private var stepper:NumericStepper;
		
		public function Main()
		{
			srcArea = new TextArea(this, 0, 0, "FLASH");
			destArea = new TextArea(this, 0, 0);
			
			srcArea.width = destArea.width = stage.stageWidth;
			srcArea.height = 100;
			
			stepper = new NumericStepper(this, 150, srcArea.height + 10);
			stepper.value = 3;
			new PushButton(this, 0, srcArea.height + 10, "Encryption", onClick);
			
			destArea.y = stepper.y + 50;
			destArea.height = stage.stageHeight - destArea.y;
		
			onClick();
		}
		
		private function onClick(event:Event = null):void
		{
			destArea.text = shift(srcArea.text, stepper.value);
		}
		
		private function shift(src:String, key:int):String
		{
			var table:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			var dest:String = "";
			
			for (var i:int = 0; i < src.length; i++)
			{
				var char:String = src.charAt(i);
				var pos:int = table.indexOf(char);
				pos += key;
				pos %= 26;
				if (pos < 0) pos += 26;
				
				dest += table.charAt(pos);
			}
			
			return dest;
		}
	}
}