Direction detection

based on http://www.kirupa.com/developer/actionscript/detecting_mouse_direction.htm
what it does is, it draws either 10 pixls right, when u move your mouse right, it moves 10 pixls left when u move your mouse left etc, and it draws 10 pxls up, left down, right depending on how u move ur mouse

Mouse.hide();
var posX:Number = 275;
var posY:Number = 400;
var chang:Number = 10;
this.createEmptyMovieClip(“branch_mc”, -1000);
branch_mc.lineStyle(0.25, 0xff0000, 100);
branch_mc.moveTo(posX, posY);
checkX = function (dx, oldVal, newVal) {
if (oldVal<newVal && posX<550) {
trace(“moving right”);
posX = posX+chang;
branch_mc.lineTo(posX, posY);
} else if (oldVal>newVal && posX>0) {
trace(“moving left”);
posX = posX-chang;
branch_mc.lineTo(posX, posY);
}
return newVal;
};
checkY = function (dy, oldVal, newVal) {
if (oldVal<newVal && posY<400) {
trace(“down”);
posY = posY+chang;
branch_mc.lineTo(posX, posY);
} else if (oldVal>newVal && posY>0) {
trace(“up”);
posY = posY-chang;
branch_mc.lineTo(posX, posY);
}
return newVal;
};
this.watch(“xdir”, checkX);
this.watch(“ydir”, checkY);
this.onMouseMove = function() {
xdir = _xmouse;
ydir = _ymouse;
};
this.onEnterFrame = function() {
this.attachMovie(“ball”, “ball”, 200);
this.ball._x = posX;
this.ball._y = posY;
};

if u want to use this script by copying it, u need to create a movieclip(a circle or a rectangle) name it ball, and make it at properties export to actionScript

an interesting effect, nice.

very cool, you can make drawing competitions with this :stuck_out_tongue: only annoying bug is that the square isn’t where the mouse. It gets really annoying when you think your mouse is where the square is but is in fact somewhere else…

its nice :slight_smile:
but as ^ said the box doesnot exactly match movements of the mouse

that’s on purpouse
for each movement of the mouse the square moves 10 pixel
it’s indirect proportional

good one