Copy link to clipboard
Copied
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); }
Copy link to clipboard
Copied
don't remove the eventlistener.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now