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

Mouse Direction AS3.0

Mouse Direction AS3.0
* This script checks the direction of the mouse, it can have update and xy sensetivity
* It uses Enterframe and inline's to check the absolute position of the mouse on the stage
Get Adobe Flash player
by lewis_c1986 07 Apr 2010
/**
 * Copyright lewis_c1986 ( http://wonderfl.net/user/lewis_c1986 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6One
 */


/*
 * Mouse Direction AS3.0
 * This script checks the direction of the mouse, it can have update and xy sensetivity
 * It uses Enterframe and inline's to check the absolute position of the mouse on the stage
 */
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    public class FlashTest extends Sprite {
    		private var lastX:Number = 0;
    		private var lastY:Number = 0;
    		//sensetivity tweaking vars
		private var update:Number = 0;
    		private var sensetivity:Number = 1;
    		private var Xadj:Number = 1;
    		private var Yadj:Number = 1;
    		
    		private var xDir:String = "still";
    		private var yDir:String = "still";
    		private var tf:TextField = new TextField();
        public function FlashTest() {
            // write as3 code here..
			addChild(tf);
			tf.text = "bob";
			tf.autoSize = "left";
            addEventListener(Event.ENTER_FRAME, mouseMove);
        }
        private function mouseMove(e:Event):void
        {
        		mouseDir(e);
        		tf.text = "direction"+" x:"+xDir+" y:"+yDir;
        }
        private function mouseDir(e:Event):void
        {
        		if(update == sensetivity)
        		{
	        		//relative mouse tracking
 	       		xDir = (mouseX > lastX+Xadj) ? ("right") : ((mouseX < lastX-Xadj) ? ("left") : ("still"));
  	      		yDir = (mouseY > lastY+Yadj) ? ("down") : ((mouseY < lastY-Yadj) ? ("up") : ("still"));
        		
				lastX = mouseX;
				lastY = mouseY;
				update = 0;
        		}
			else
				update++;
        }
    }
}