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

MouseDirection() Script

Get Adobe Flash player
by bradsedito 16 Sep 2013
    Embed
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kUqJ
 */






// Mouse Direction ActionScript 3.0:
//
//* Code 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 MouseDirection extends Sprite 
    {
    //  Dynamic Property Var's:  
        private var lastX:Number = 0;
        private var lastY:Number = 0;
    
    //  Sensitivity-Tweaking Var's:
        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 MouseDirection() 
        {
            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++;
        }
        
        
    }
}