Flash 中的墨西哥波浪效果
我正在尝试复制“墨西哥波浪”的运动。我正在使用Flash CS5,并使用AS2。
我创建了一个“跳跃”图形,并在剪辑中对其进行了动画处理,使其跳跃一次,然后落回地面。我已将剪辑拉入主时间线并复制了很多次,因此我有一排“跳线”。我给每个实例一个唯一的 ID。然后,我使用以下代码告诉每个剪辑实例按顺序开始播放:
var total_jumpers = 36;
var i = 0;
var jumpLag = 1000;
function do_jump(bottle) {
jumper.play();
}
for( i=1; i<=total_jumpers; i++)
{
var mcName:String = "b" + i;
jump = setInterval(do_jump,jumpLag,this[mcName]);
trace("Jumper " + mcName + ". Lag: " + jumpLag);
jumpLag += 100;
}
clearInterval(jump);
stop();
在剪辑中,我将 stop() 放在最后一帧中以尝试停止其循环。
所以这工作正常,但剪辑似乎循环 - 我无法让它们停止。
我将不胜感激任何见解/帮助。
I'm trying to replicate the motion of a 'mexican wave'. I am using Flash CS5, and using AS2.
I've created a 'jumper' graphic and animated it in a clip so it jumps once - up then falls back to the ground. I've pulled the clip in to the main timeline and replicated a bunch of times so I have a row of 'jumpers'. I've given each instance a unique ID. Then I'm telling each clip instance to start playing, in sequence, using the following code:
var total_jumpers = 36;
var i = 0;
var jumpLag = 1000;
function do_jump(bottle) {
jumper.play();
}
for( i=1; i<=total_jumpers; i++)
{
var mcName:String = "b" + i;
jump = setInterval(do_jump,jumpLag,this[mcName]);
trace("Jumper " + mcName + ". Lag: " + jumpLag);
jumpLag += 100;
}
clearInterval(jump);
stop();
In the clip, I have put stop() in the last frame to try and stop it looping.
So this works ok, but the clips seem to loop – I can't get them to stop.
I would be grateful for any insight / assistance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
setInterval
可能不是执行此操作的最佳方法,因为它会不断重复,直到调用clearinterval
为止。setInterval
为每个调用返回不同的 ID -将其视为每个计时器的唯一 ID。调用
clearInterval
的代码实际上只是清除最后一个间隔。需要为setInterval
返回的每个 ID 调用clearInterval
。这需要将 ID 存储在数组中,然后在动画开始后调用特定 ID 的clearInterval
。更好的方法是使用 setTimeout(请参阅 flash.utils.setTimeout),因为它只运行一次然后就终止,这意味着您不需要额外的逻辑来停止计时器。
setInterval
is probably not the best way to do this because it repeats continuously untilclearinterval
is called..setInterval
returns a different ID for each call - think of it as the unique ID for each timer.The code which calls
clearInterval
it's actually only clearing the last interval.clearInterval
needs to be called for each ID returned bysetInterval
. This would require storing the IDs in an array, then calling theclearInterval
for the specific ID after the animation has started.A better way to do this would be to use
setTimeout
(see flash.utils.setTimeout) because it only runs once and then dies, meaning you will not need the extra logic to stop the timer.