DFdou's Blog Life is short,Be yourself.

610/080

Flash 鼠标拖动MC的缓动控制

先看下效果:

代码:

[sourcecode language='js']
import mx.transitions.Tween;
import mx.transitions.easing.*;
var oldX:Number;
onEnterFrame = function () {
if (hitTest(_xmouse, _ymouse, mc)) {
mc.onPress = function() {
oldX = _xmouse;
this.onMouseMove = function() {
onMove(this);
updateAfterEvent();
};
};
}
};
mc.onRelease = mc.onReleaseOutside=function () {
this.onMouseMove = function() {
};
};
function onMove(obj:Object) {
new Tween(this, "_x", Strong.easeOut, this._x, this._x+(_xmouse-oldX)*1.5, 1, true);
}
[/sourcecode]

思路是这样,由于MC里边的子MC都有各自的鼠标事件,所以用hitTest来检测鼠标是否在MC处按下。
接着就计算鼠标移动的距离,让MC Tween比鼠标移动的距离*一个系数,上边的例子里是1.5。
这样在鼠标松开时,MC会继续移动一会~

Tagged as: , , , , No Comments