Skip to main content
Participant
March 17, 2018
Question

How can I make this eye animation in Flash loop continuously after removing Event Listener?

  • March 17, 2018
  • 1 reply
  • 307 views

favorite

I have made a movieclip of an eye, which is set to play a blinking animation at random intervals. I have multiple instances on the stage, and when I play it, there's maybe 1-2 seconds of blinking and then it stops completely. How can I make it loop?

I had to add the removeEventListener at the end because Flash would crash if I didn't, I think because it was infinitely loading the function or something.

The code is placed inside the eye movie clip.

this.gotoAndStop(1); 
var eye:Eye = new Eye();
var eyeTimer = new Timer(1000 + Math.random() * 1000);
eyeTimer
.addEventListener(TimerEvent.TIMER, blink);
eyeTimer
.start();
function blink(evt:TimerEvent😞void
{ Timer(evt.currentTarget).delay = 1000 + Math.random() * 1000;  trace( "triggered!" );
this.gotoAndPlay(1); eyeTimer.removeEventListener(TimerEvent.TIMER, blink); }
This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
March 17, 2018

don't remove the eventlistener.