Hi I’m trying to add the Y coordinates to this tutorial here’s what I’ve add but can’t make it work properly, any help?
http://www.gotoandlearn.com/play.php?id=81
var bounds:Object = {left:98, right:449, up:0, down:150};
var currentX:Number = thumb.x;
var lastX:Number = thumb.x;
var vx:Number = 0;
var currentY:Number = thumb.y;
var lastY:Number = thumb.y;
var vy:Number = 0;
var isDragging:Boolean = false;
var offset:Number;
thumb.buttonMode = true;
addEventListener(Event.ENTER_FRAME, loop);
thumb.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
addEventListener(MouseEvent.MOUSE_UP, onUp);
function onDown(e:MouseEvent):void
{
isDragging = true;
offset = thumb.mouseX;
addEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
function onUp(e:MouseEvent):void
{
isDragging = false;
removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
function onMove(e:MouseEvent):void
{
thumb.x = mouseX - offset;
if(thumb.x <= bounds.left)
thumb.x = bounds.left;
else if(thumb.x >= bounds.right)
thumb.x = bounds.right;
thumb.y = mouseY - offset;
if(thumb.y <= bounds.up)
thumb.y = bounds.up;
else if(thumb.y >= bounds.down)
thumb.y = bounds.down;
e.updateAfterEvent();
}
function loop(e:Event):void
{
if(isDragging)
{
lastX = currentX;
currentX = mouseX;
vx = currentX - lastX;
lastY = currentY;
currentY = mouseY;
vy = currentY - lastY;
}
else
{
thumb.x += vx;
thumb.y += vy;
}
if(thumb.x <= bounds.left)
{
thumb.x = bounds.left;
vx *= -1;
}
else if(thumb.x >= bounds.right)
{
thumb.x = bounds.right;
vx *= -1;
}
if(thumb.y <= bounds.up)
{
thumb.y = bounds.up;
vy *= -1;
}
else if(thumb.y >= bounds.dowm)
{
thumb.y = bounds.down;
vy *= -1;
}
vx *= 0.95;
vy *= 0.95;
if(Math.abs(vx) < 0.5) vx = 0;
}