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

Reaction Time Test

Gif Version : https://twitter.com/_wad1m/status/726766447167307776?lang=en

Post : http://blog.wad1m.com/reaction-time-as3/
Get Adobe Flash player
by WLAD 01 May 2016
/**
 * Copyright WLAD ( http://wonderfl.net/user/WLAD )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/I2Rr
 */

/// @mxmlc  -o ReactionTime.swf -swf-version 15 -publisher wad1m.com
package {
	import flash.display.Sprite;
	import flash.text.Font;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.getTimer;
	[SWF( width = "465", height = "465", frameRate = "60" )]
	/// @author wad1m.com
	public class ReactionTime extends Sprite
	{
		// http://www.dafont.com/caviar-dreams.font
		//[Embed(source='embed/CaviarDreams_Bold.ttf',fontFamily  ='CaviarDreams_Bold',fontStyle   ='normal',fontWeight  ='normal',embedAsCFF='false'
		//,unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')]
		//private static const FontClass:Class;
		
		public function ReactionTime()
		{
			var reset:Boolean = false;
			var click:Boolean = false;
			var loop:Boolean = true;
			var ms:int = 0;
			
			stage.align = "tl";
			stage.scaleMode = "noScale";
			stage.addEventListener('rightMouseDown', function(_:*):void{} );
			
			//Font.registerFont( FontClass );
			
			var textFormat:TextFormat = new TextFormat();
			textFormat.size = 96;
			textFormat.align = 'center';
			textFormat.color = 0xFFFFFF;
			//textFormat.font = 'CaviarDreams_Bold';
			
			var textField:TextField = new TextField();
			textField.defaultTextFormat = textFormat;
			textField.autoSize = 'left';
			textField.sharpness = -100;
			textField.antiAliasType = 'advanced';
			//textField.embedFonts = true;
			textField.mouseEnabled = false;
			
			stage.addChild( textField );
			
			function alignText():void {
				
				textField.x = ( stage.stageWidth - textField.width ) >> 1;
				textField.y = ( stage.stageHeight - textField.height ) >> 1;
			};
			
			loop = true;
			color = 0x48A9F9;
			textField.text = "Ready";
			alignText();
			var start:int = getTimer();
			var kick:int = 1000 + int ( 2000 * Math.random() );
			
			addEventListener('enterFrame', function(_:*):void {
				
				if ( ! loop ) return;
				
				var time:int = getTimer();
				
				if ( time - start > kick )
				{
					color = 0x7CEA0F;
					
					click = true;
					
					ms = ( time - start - kick );
					
					textField.text = " CLICK!\n" + ms + "\n" + "ms";
					
					alignText();
				}
			});
			
			stage.addEventListener('mouseDown', function(_:*):void {
				
				if ( reset ) 
				{
					reset = false;
					click = false;
					loop = true;
					color = 0x48A9F9;
					textField.text = "Ready";
					alignText();
					start = getTimer();
					kick = 1000 + int ( 2000 * Math.random() );
				}
				else if ( click ) 
				{
					color = 0x49F8C4;
					
					textField.text = ms + " " + "ms";
					
					alignText();
					
					loop = false;
					
					reset = true;
				}
				else
				{
					kick += 1500;
				}
			});
		}
		
		private var _color:uint = 0;
		private function set color( val:uint ):void
		{
			if ( val == _color ) return;
			
			_color = val;
			graphics.clear();
			graphics.beginFill( val );
			graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
			graphics.endFill();
		}
	}
}