AS2:鼠标移动太快扰乱功能

发布于 2024-11-11 13:59:19 字数 2710 浏览 2 评论 0原文

我使用以下代码作为一组可滚动条的一部分,以便在拖动一个条时更改每个条相对于另一个条的关系。它会一直工作,直到用户尽可能快地滑动栏,然后数字就会出错......我确信这个功能无法像鼠标一样快速处理,但有人知道解决这个问题的方法吗?

onClipEvent (load) {
    Symptoms_sliders = new Array(this._parent.slider1.slider, this._parent.slider2.slider, this._parent.slider3.slider, this._parent.slider4.slider, this._parent.slider5.slider);
    Food_sliders = new Array(this._parent.slider6.slider, this._parent.slider7.slider, this._parent.slider8.slider, this._parent.slider9.slider);
    for (i=0; i<Food_sliders.length; i++) {
        Food_sliders[i]._y = 75;
    }
    is_scrolling = 0;
    function Food_scroll_ratio() {
        init_scroll_diff = init_scroll_num-init_scroll._y;
        Slider_ratio = new Array();
        totalLeft = init_scroll_num;
        while (_global.init_moved != init_scroll._y) {
            for (i=0; i<Food_sliders.length; i++) {
                if (Food_sliders[i] != init_scroll) {
                    slider_pos = Food_sliders[i]._y;
                    percentageOf = ((100-init_slider_pos[i])/totalLeft)*100;
                    percentageMultiplier = 100/percentageOf;
                    trace(percentageMultiplier);
                    if (init_scroll_num == 0) {
                        scroll_change = Math.round(Math.abs(init_scroll_diff/3));
                    } else {
                        scroll_change = Math.round(Math.abs(init_scroll_diff)/percentageMultiplier);
                    }
                    if (percentageOf == Infinity) {
                        Food_sliders[i]._y = 100;
                    } else if (init_scroll_diff>0) {
                        Food_sliders[i]._y = init_slider_pos[i]+scroll_change;
                    } else if (init_scroll_diff<0) {
                        Food_sliders[i]._y = init_slider_pos[i]-scroll_change;
                    }

                }
            }
            _global.init_moved = init_scroll._y;

        }
    }
}
onClipEvent (mouseMove) {
    for (i=0; i<Food_sliders.length; i++) {
        Food_sliders[i].onPress = function() {
            startDrag(this, false, 0, 100, 0, 0);
            init_scroll_num = this._y;
            init_scroll = this;
            is_scrolling = 1;
            init_slider_pos = new Array();
            init_slider_pos.push(Food_sliders[0]._y);
            init_slider_pos.push(Food_sliders[1]._y);
            init_slider_pos.push(Food_sliders[2]._y);
            init_slider_pos.push(Food_sliders[3]._y);
        };
        Food_sliders[i].onRelease = Food_sliders[i].onReleaseOutside=function () {
            stopDrag();
            is_scrolling = 0;
        };
    }
    if (is_scrolling == 1) {
        Food_scroll_ratio();
    }
}

I am using the following code as part of a set of scrollable bars to change each bar in relation to another when one is dragged. It works until the user swipes the bar as fast as possible then the numbers go wrong... I'm sure this is the function unable to process as fast as the mouse but anyone know a way around this?

onClipEvent (load) {
    Symptoms_sliders = new Array(this._parent.slider1.slider, this._parent.slider2.slider, this._parent.slider3.slider, this._parent.slider4.slider, this._parent.slider5.slider);
    Food_sliders = new Array(this._parent.slider6.slider, this._parent.slider7.slider, this._parent.slider8.slider, this._parent.slider9.slider);
    for (i=0; i<Food_sliders.length; i++) {
        Food_sliders[i]._y = 75;
    }
    is_scrolling = 0;
    function Food_scroll_ratio() {
        init_scroll_diff = init_scroll_num-init_scroll._y;
        Slider_ratio = new Array();
        totalLeft = init_scroll_num;
        while (_global.init_moved != init_scroll._y) {
            for (i=0; i<Food_sliders.length; i++) {
                if (Food_sliders[i] != init_scroll) {
                    slider_pos = Food_sliders[i]._y;
                    percentageOf = ((100-init_slider_pos[i])/totalLeft)*100;
                    percentageMultiplier = 100/percentageOf;
                    trace(percentageMultiplier);
                    if (init_scroll_num == 0) {
                        scroll_change = Math.round(Math.abs(init_scroll_diff/3));
                    } else {
                        scroll_change = Math.round(Math.abs(init_scroll_diff)/percentageMultiplier);
                    }
                    if (percentageOf == Infinity) {
                        Food_sliders[i]._y = 100;
                    } else if (init_scroll_diff>0) {
                        Food_sliders[i]._y = init_slider_pos[i]+scroll_change;
                    } else if (init_scroll_diff<0) {
                        Food_sliders[i]._y = init_slider_pos[i]-scroll_change;
                    }

                }
            }
            _global.init_moved = init_scroll._y;

        }
    }
}
onClipEvent (mouseMove) {
    for (i=0; i<Food_sliders.length; i++) {
        Food_sliders[i].onPress = function() {
            startDrag(this, false, 0, 100, 0, 0);
            init_scroll_num = this._y;
            init_scroll = this;
            is_scrolling = 1;
            init_slider_pos = new Array();
            init_slider_pos.push(Food_sliders[0]._y);
            init_slider_pos.push(Food_sliders[1]._y);
            init_slider_pos.push(Food_sliders[2]._y);
            init_slider_pos.push(Food_sliders[3]._y);
        };
        Food_sliders[i].onRelease = Food_sliders[i].onReleaseOutside=function () {
            stopDrag();
            is_scrolling = 0;
        };
    }
    if (is_scrolling == 1) {
        Food_scroll_ratio();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春夜浅 2024-11-18 13:59:19

这个问题仍然发生,我认为它无法避免,但我使用另一个函数(Slider_checker),每次鼠标滚动滚动条时,该函数都会在鼠标空闲 20 毫秒后运行一次(这 20 毫秒允许它确保 Food_Scroll_ratio 的所有循环都完成,这样就不会干扰它并节省一些 cpu 周期)。

这是我的最终代码:

onClipEvent (load) {
    Symptoms_sliders = new Array(this._parent.slider1.slider, this._parent.slider2.slider, this._parent.slider3.slider, this._parent.slider4.slider, this._parent.slider5.slider);
    Food_sliders = new Array(this._parent.slider6.slider, this._parent.slider7.slider, this._parent.slider8.slider, this._parent.slider9.slider);
    for (i=0; i<Food_sliders.length; i++) {
        Food_sliders[i]._y = 75;
    }
    is_scrolling = 0;
    Slider_check_interval = 0;
    var mouseTimerID:Number;
    var delay:Number = 50;
    var mouseMoveListener = new Object();
    mouseMoveListener.onMouseMove = function() {
        clearInterval(mouseTimerID);
        mouseTimerID = setInterval(Slider_checker, delay);
    };
    Slider_checker = function () {
        while (Slider_check_interval == 1) {
            count = 0;
            for (i=0; i<Food_sliders.length; i++) {
                count += 100-Food_sliders[i]._y;
            }
            if (count != 100 && count != 0) {
                mxm = Food_sliders[0];
                for (i=0; i<Food_sliders.length; i++) {
                    if (Food_sliders[i]._y<mxm._y) {
                        mxm = Food_sliders[i];
                    }
                }
                if (count>100) {
                    mxm._y += count-100;
                }
                if (count<100) {
                    mxm._y -= 100-count;
                }
            }
            Slider_check_interval = 0;
        }
    };


    Mouse.addListener(mouseMoveListener);
    function Food_scroll_ratio() {
        init_scroll_diff = init_scroll_num-init_scroll._y;
        totalLeft = init_scroll_num;
        Slider_check = new Array();
        for (i=0; i<Food_sliders.length; i++) {
            if (Food_sliders[i] != init_scroll) {
                slider_pos = Food_sliders[i]._y;
                percentageOf = ((100-init_slider_pos[i])/totalLeft)*100;
                percentageMultiplier = 100/percentageOf;
                if (init_scroll_num == 0) {
                    scroll_change = Math.round(Math.abs(init_scroll_diff/3));
                } else {
                    scroll_change = Math.round(Math.abs(init_scroll_diff)/percentageMultiplier);
                }
                if (percentageOf == Infinity) {
                    Food_sliders[i]._y = 100;
                } else if (init_scroll_diff>0) {
                    Food_sliders[i]._y = init_slider_pos[i]+scroll_change;
                } else if (init_scroll_diff<0) {
                    Food_sliders[i]._y = init_slider_pos[i]-scroll_change;
                }
            }
        }
        Slider_check_interval = 1;
    }
}
onClipEvent (mouseMove) {
    for (i=0; i<Food_sliders.length; i++) {
        Food_sliders[i].onPress = function() {
            startDrag(this, false, 0, 100, 0, 0);
            init_scroll_num = this._y;
            init_scroll = this;
            is_scrolling = 1;
            init_slider_pos = new Array();
            init_slider_pos.push(Food_sliders[0]._y);
            init_slider_pos.push(Food_sliders[1]._y);
            init_slider_pos.push(Food_sliders[2]._y);
            init_slider_pos.push(Food_sliders[3]._y);
        };
        Food_sliders[i].onRelease = Food_sliders[i].onReleaseOutside=function () {
            stopDrag();
            is_scrolling = 0;
        };

    }
    if (is_scrolling == 1) {
        Food_scroll_ratio();
    }
}

This problem still occurs and I don't think it can be avoided but I use another function (Slider_checker) that runs once 20ms after the mouse is idle everytime the mouse scrolls a scrollbar (the 20ms allows it to ensure that all loops of Food_Scroll_ratio are finished so nothing interferes with it and saves some cpu cycles).

Here is my final code:

onClipEvent (load) {
    Symptoms_sliders = new Array(this._parent.slider1.slider, this._parent.slider2.slider, this._parent.slider3.slider, this._parent.slider4.slider, this._parent.slider5.slider);
    Food_sliders = new Array(this._parent.slider6.slider, this._parent.slider7.slider, this._parent.slider8.slider, this._parent.slider9.slider);
    for (i=0; i<Food_sliders.length; i++) {
        Food_sliders[i]._y = 75;
    }
    is_scrolling = 0;
    Slider_check_interval = 0;
    var mouseTimerID:Number;
    var delay:Number = 50;
    var mouseMoveListener = new Object();
    mouseMoveListener.onMouseMove = function() {
        clearInterval(mouseTimerID);
        mouseTimerID = setInterval(Slider_checker, delay);
    };
    Slider_checker = function () {
        while (Slider_check_interval == 1) {
            count = 0;
            for (i=0; i<Food_sliders.length; i++) {
                count += 100-Food_sliders[i]._y;
            }
            if (count != 100 && count != 0) {
                mxm = Food_sliders[0];
                for (i=0; i<Food_sliders.length; i++) {
                    if (Food_sliders[i]._y<mxm._y) {
                        mxm = Food_sliders[i];
                    }
                }
                if (count>100) {
                    mxm._y += count-100;
                }
                if (count<100) {
                    mxm._y -= 100-count;
                }
            }
            Slider_check_interval = 0;
        }
    };


    Mouse.addListener(mouseMoveListener);
    function Food_scroll_ratio() {
        init_scroll_diff = init_scroll_num-init_scroll._y;
        totalLeft = init_scroll_num;
        Slider_check = new Array();
        for (i=0; i<Food_sliders.length; i++) {
            if (Food_sliders[i] != init_scroll) {
                slider_pos = Food_sliders[i]._y;
                percentageOf = ((100-init_slider_pos[i])/totalLeft)*100;
                percentageMultiplier = 100/percentageOf;
                if (init_scroll_num == 0) {
                    scroll_change = Math.round(Math.abs(init_scroll_diff/3));
                } else {
                    scroll_change = Math.round(Math.abs(init_scroll_diff)/percentageMultiplier);
                }
                if (percentageOf == Infinity) {
                    Food_sliders[i]._y = 100;
                } else if (init_scroll_diff>0) {
                    Food_sliders[i]._y = init_slider_pos[i]+scroll_change;
                } else if (init_scroll_diff<0) {
                    Food_sliders[i]._y = init_slider_pos[i]-scroll_change;
                }
            }
        }
        Slider_check_interval = 1;
    }
}
onClipEvent (mouseMove) {
    for (i=0; i<Food_sliders.length; i++) {
        Food_sliders[i].onPress = function() {
            startDrag(this, false, 0, 100, 0, 0);
            init_scroll_num = this._y;
            init_scroll = this;
            is_scrolling = 1;
            init_slider_pos = new Array();
            init_slider_pos.push(Food_sliders[0]._y);
            init_slider_pos.push(Food_sliders[1]._y);
            init_slider_pos.push(Food_sliders[2]._y);
            init_slider_pos.push(Food_sliders[3]._y);
        };
        Food_sliders[i].onRelease = Food_sliders[i].onReleaseOutside=function () {
            stopDrag();
            is_scrolling = 0;
        };

    }
    if (is_scrolling == 1) {
        Food_scroll_ratio();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文