1个回答
展开全部
list_mc 是要移动的对象(MC),之前写滑动效果没有实现鼠标跟随,这次加上了鼠标跟随,还有缓冲的效果,同时需要判断鼠标滑动的角度和滑动的距离,AS 代码如下:
root = this;
root.k = 3;
// 移动的宽度
root.blockWidth = 300;
root.enabledMove = false;
root.enRun = false;
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
if (root.enRun == true) { // 这次动作没完成,不能进行第二次
return;
}
root.enRun = true;
root.startX = _xmouse;
root.startY = _ymouse;
// 目标的 _x 初始位置
root.mcStartX = root.list_mc._x;
root.onEnterFrame = function() {
root.endX = _xmouse;
root.endY = _ymouse;
xx = Math.abs(root.endX-root.startX);
yy = Math.abs(root.endX-root.startY);
cc = Math.sqrt((xx*xx)+(yy*yy));
if (cc == 0) {
corner = 0;
} else {
corner = (yy/cc)*90;
}
//trace('xx:'+xx);
if (corner<50 && xx>120) {
root.enabledMove = true;
moveBa();
}
};
};
mouseListener.onMouseUp = function() {
if (root.enabledMove == true) { // 鼠标点击,需要移动后才能执行
root.enabledMove == false;
root.endX = _xmouse;
delete root.onEnterFrame;
root.onEnterFrame = function() {
moveBa();
};
}
};
Mouse.addListener(mouseListener);
function moveBa() {
//mcEndX = root.mcStartX+(root.endX-root.startX);
if ((root.endX-root.startX)>0) {
offset = root.blockWidth;
} else {
offset = -root.blockWidth;
}
mcEndX = root.mcStartX+offset;
//trace(mcEndX+":"+root.list_mc._x);
root.list_mc._x += (mcEndX-root.list_mc._x)/root.k;
if (Math.abs((mcEndX-root.list_mc._x))<1) {
root.list_mc._x = mcEndX;
trace(root.list_mc._x);
root.enRun = false;
delete root.onEnterFrame;
}
}
root = this;
root.k = 3;
// 移动的宽度
root.blockWidth = 300;
root.enabledMove = false;
root.enRun = false;
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
if (root.enRun == true) { // 这次动作没完成,不能进行第二次
return;
}
root.enRun = true;
root.startX = _xmouse;
root.startY = _ymouse;
// 目标的 _x 初始位置
root.mcStartX = root.list_mc._x;
root.onEnterFrame = function() {
root.endX = _xmouse;
root.endY = _ymouse;
xx = Math.abs(root.endX-root.startX);
yy = Math.abs(root.endX-root.startY);
cc = Math.sqrt((xx*xx)+(yy*yy));
if (cc == 0) {
corner = 0;
} else {
corner = (yy/cc)*90;
}
//trace('xx:'+xx);
if (corner<50 && xx>120) {
root.enabledMove = true;
moveBa();
}
};
};
mouseListener.onMouseUp = function() {
if (root.enabledMove == true) { // 鼠标点击,需要移动后才能执行
root.enabledMove == false;
root.endX = _xmouse;
delete root.onEnterFrame;
root.onEnterFrame = function() {
moveBa();
};
}
};
Mouse.addListener(mouseListener);
function moveBa() {
//mcEndX = root.mcStartX+(root.endX-root.startX);
if ((root.endX-root.startX)>0) {
offset = root.blockWidth;
} else {
offset = -root.blockWidth;
}
mcEndX = root.mcStartX+offset;
//trace(mcEndX+":"+root.list_mc._x);
root.list_mc._x += (mcEndX-root.list_mc._x)/root.k;
if (Math.abs((mcEndX-root.list_mc._x))<1) {
root.list_mc._x = mcEndX;
trace(root.list_mc._x);
root.enRun = false;
delete root.onEnterFrame;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询