开发者

AS3: Delay Enter Frame Animation

I've got a fade out animation using ENTER_FRAME. I want the fade out to start after 2-3 seconds. How can I create this delay?

txtAlert.addEventListener(Eve开发者_运维知识库nt.ENTER_FRAME,animAlert);

function animAlert(e:Event) {
    if(e.target.alpha>0) {
        e.target.alpha-=0.01;
    } else {
        e.target.parent.removeChild(e.target);
        e.target.removeEventListener(Event.ENTER_FRAME,animAlert);
    }
}


You should use a Timer:

var timer:Timer = new Timer(3000, 1);
    timer.addEventListener(TimerEvent.TIMER, action);
    timer.start();

function action(evt:TimerEvent):void{
     txtAlert.addEventListener(Event.ENTER_FRAME,animAlert);

     trace("Times Fired: " + evt.currentTarget.currentCount);
     trace("Time Delayed: " + evt.currentTarget.delay);
}

BTW you should look at animation libraries like Twiner that will make your life a lot easier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜