我期待为我的滚动字段添加一个自动滚动功能,当用户将鼠标悬停在文本或任何控件上时,该滚动字段会停止。我对编程还很陌生,不知道如何去做。Flash AS2自动滚动文本字段
这里是工作的滚动代码:
// ---- Scroll Bar Code ---- //
fscommand("allowscale", "false");
bar.useHandCursor = dragger.useHandCursor=false;
space = 20;
friction = 0.9;
speed = 4;
y = dragger._y;
top = main._y;
bottom = (main._y + mask_mc._height) - (main._height - space);
//when scroll button is selected
dragger.onPress = function() {
drag = true;
this.startDrag(false, this._x, this._parent.y, this._x, this._parent.y + this._parent.bar._height - this._height);
dragger.scrollEase();
};
//when scroll button is released
dragger.onMouseUp = function() {
this.stopDrag();
drag = false;
};
//when any of the scroll bar is pressed
bar.onPress = function() {
drag = true;
if (this._parent._ymouse > ((this._y + this._height) - this._parent.dragger._height)) {
this._parent.dragger._y = this._parent._ymouse;
this._parent.dragger._y = (this._y + this._height) - this._parent.dragger._height;
} else {
this._parent.dragger._y = this._parent._ymouse;
}
dragger.scrollEase();
};
//when scroll bar is released
bar.onMouseUp = function() {
drag = false;
};
//when scroll button is dragged
moveDragger = function (d) {
if ((dragger._y >= ((y + bar._height) - dragger._height) && d == 1) || (dragger._y <= y && d == -1)) {
clearInterval(myInterval);
} else {
dragger._y += d;
dragger.scrollEase();
updateAfterEvent();
}
};
//when up button is pressed
up_btn.onPress = function() {
myInterval = setInterval(moveDragger, 18, -1);
};
//when down button is pressed
down_btn.onPress = function() {
myInterval = setInterval(moveDragger, 18, 1);
};
//when up button is released
up_btn.onMouseUp = down_btn.onMouseUp = function() {
clearInterval(myInterval);
};
MovieClip.prototype.scrollEase = function() {
this.onEnterFrame = function() {
if (Math.abs(dy) == 0 && drag == false) {
delete this.onEnterFrame;
}
r = (this._y - y)/(bar._height - this._height);
dy = Math.round((((top - (top-bottom) * r) - main._y)/speed) * friction);
main._y += dy;
};
};
//End Scroll Bar Code
dragger.onRollOver = function() {
dragger.useHandCursor = false;
}
// Start AutoScroll
var my_timedProcess:Number = setTimeout(autoScroll, 2000, "two second delay");
// Define AutoScroll
function autoScroll() {
scrollInterval = setInterval(moveDragger, 150, 1);
}
//Stop AutoScroll on Rollover
mask_mc.onRollOver = down_btn.onRollOver = up_btn.onRollOver = dragger.onRollOver = bar.onRollOver = function() {
clearInterval(scrollInterval);
};
//Start AutoScroll on RollOut
mask_mc.onRollOut = down_btn.onRollOut = up_btn.onRollOut = function() {
scrollInterval = setInterval(moveDragger, 150, 1);
};
感谢您的帮助。通过玩你的代码并重新检查我正在处理的事情,我能够找到一种方法来利用moveDragger函数,以便为我自动滚动。自动滚动代码可以在我的原始帖子的底部找到。 – nr20 2014-09-19 18:44:51
很高兴帮助。如果我的回答有帮助,你可以投票。 – Fergoso 2014-09-20 01:58:17