AS3循环动画

时间:2015-10-08 23:44:06

标签: actionscript-3 flash timer

我在AS3中创建了一个图像旋转横幅,基本上是连续循环中的FadesIn和FadesOut。我希望横幅循环3次然后停止,我很难让它在3次循环后停止。好吧,我对AS3很新。这是下面的代码。请帮助!!

谢谢!

import flash.utils.Timer;
import flash.events.TimerEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;

mc1.alpha = 0;
mc2.alpha = 0;
mc3.alpha = 0;
var counter;

var timer:Timer = new Timer(1000,9);
timer.addEventListener(TimerEvent.TIMER,timerListener);
timer.start();

function timerListener(event:TimerEvent):void
{
    if (timer.currentCount == 1){

    if (counter==1){ var tween6:Tween = new Tween(mc3,"alpha",Strong.easeOut,1,0,1,true)}// fade out routine over 1 sec
    var tween1:Tween = new Tween(mc1,"alpha",Strong.easeOut,0,1,2,true)// fade in routine over 2 seconds

}


if (timer.currentCount == 4)
{
    var tween2:Tween = new Tween(mc1,"alpha",Strong.easeOut,1,0,1,true);//  fade out routine
    var tween3:Tween = new Tween(mc2,"alpha",Strong.easeOut,0,1,2,true);//fade in routine
}

if (timer.currentCount == 7)
{
    var tween4:Tween = new Tween(mc2,"alpha",Strong.easeOut,1,0,1,true);//  fade out routine
    var tween5:Tween = new Tween(mc3,"alpha",Strong.easeOut,0,1,2,true);// fade in routine

}

if (timer.currentCount == 9)//reset routine
    {
    counter = 1;
    timer.reset();
    timer.start();

}
}

1 个答案:

答案 0 :(得分:0)

许多不同的方法可以做到这一点;但是,看起来你已经有counter个对象;所以,让我们用它。

您依靠计时器的currentCount来确定要播放的幻灯片和动画。

timer.currentCount达到9时,您将counter设置为1。

if (timer.currentCount == 9) {
    counter = 1;

不是将其设置为1,而是将其递增,以便每次传递其值都会增加。

if (timer.currentCount == 9) {
    counter++;

然后,当counter等于3时,不要启动计时器。

突出显示相关代码:

// initialize your counter
var counter = 0;

/* ... */

if (timer.currentCount == 9) {
    counter++;
    timer.reset();

    if (counter < 3)
        timer.start();
}