AS2:拖动时Flash运行功能
我正在使用以下代码...我想仅在移动可拖动影片剪辑时而不是在刚刚按下它时运行函数 Food_scroll_ratio()
但不知道如何执行。
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 = 100-(100-init_scroll._y);
for (i=0; i<Food_sliders.length; i++) {
if (Food_sliders[i] != init_scroll) {
slider_pos = Food_sliders[i]._y;
percentageOf = (init_slider_pos[i]/totalLeft)*100;
percentageMultiplier = 100/percentageOf;
scroll_change = Math.abs(init_scroll_diff)/percentageMultiplier;
trace(scroll_change);
if (init_scroll_diff>0) {
Food_sliders[i]._y = slider_pos+scroll_change;
}
if (init_scroll_diff<0) {
Food_sliders[i]._y = slider_pos-scroll_change;
}
}
}
}
}
onClipEvent (enterFrame) {
for (i=0; i<Food_sliders.length; i++) {
Food_sliders[i].onMouseDown = function() {
};
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(100-Food_sliders[0]._y);
init_slider_pos.push(100-Food_sliders[1]._y);
init_slider_pos.push(100-Food_sliders[2]._y);
init_slider_pos.push(100-Food_sliders[3]._y);
};
Food_sliders[i].onRelease = Food_sliders[i].onReleaseOutside=function () {
stopDrag();
is_scrolling = 0;
};
}
if (is_scrolling == 1) {
Food_scroll_ratio();
}
}
帮助感谢欢呼
已解决
谢谢我在剪辑事件上使用了 onMouseMove 和 while 循环的组合,如下所示:
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;
}
I am using the following code... I want to run the function Food_scroll_ratio()
only when the draggable movieclip is being moved and not while it is just pressed but can't work out how to do it.
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 = 100-(100-init_scroll._y);
for (i=0; i<Food_sliders.length; i++) {
if (Food_sliders[i] != init_scroll) {
slider_pos = Food_sliders[i]._y;
percentageOf = (init_slider_pos[i]/totalLeft)*100;
percentageMultiplier = 100/percentageOf;
scroll_change = Math.abs(init_scroll_diff)/percentageMultiplier;
trace(scroll_change);
if (init_scroll_diff>0) {
Food_sliders[i]._y = slider_pos+scroll_change;
}
if (init_scroll_diff<0) {
Food_sliders[i]._y = slider_pos-scroll_change;
}
}
}
}
}
onClipEvent (enterFrame) {
for (i=0; i<Food_sliders.length; i++) {
Food_sliders[i].onMouseDown = function() {
};
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(100-Food_sliders[0]._y);
init_slider_pos.push(100-Food_sliders[1]._y);
init_slider_pos.push(100-Food_sliders[2]._y);
init_slider_pos.push(100-Food_sliders[3]._y);
};
Food_sliders[i].onRelease = Food_sliders[i].onReleaseOutside=function () {
stopDrag();
is_scrolling = 0;
};
}
if (is_scrolling == 1) {
Food_scroll_ratio();
}
}
Help appreciated cheers
Solved
Thanks I used a combination onMouseMove on the clip event and a while loop as shown below:
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 onMouseMove 而不是 onEnterFrame 进行拖动,否则会变得不稳定!如果您检查 onMouseMove + onMouseDown,这也将解决您的问题。或者您也可以使用内置的 onDrag。
You should use onMouseMove instead of onEnterFrame for dragging or it will become choppy! That will also solve your problem, if you check for onMouseMove + onMouseDown. Or alternatively you can use the built in onDrag.