0

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(Event.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);
    }
}
shannoga
  • 19,649
  • 20
  • 104
  • 169
Abdulla
  • 1,117
  • 4
  • 21
  • 44

1 Answers1

4

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.

shannoga
  • 19,649
  • 20
  • 104
  • 169
  • 1
    I don't know the Twiner library, but Greensock's TweenMax (http://www.greensock.com/tweenmax/) is a very well known library for scripted animation, very stable and flexible. – epologee Feb 07 '11 at 20:35