# Event.Enter\_Frame dying too soon?

**URL:** <https://forum.kirupa.com/t/event-enter-frame-dying-too-soon/302729>\
**Category:** flash\
**Created:** [January 6, 2010, 4:36pm UTC](https://forum.kirupa.com/t/event-enter-frame-dying-too-soon/302729 "2010-01-06T16:36:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loud](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@Loud](https://forum.kirupa.com/u/Loud)\
**Post date:** [January 6, 2010, 4:36pm UTC](https://forum.kirupa.com/t/event-enter-frame-dying-too-soon/302729/1 "2010-01-06T16:36:28Z")

</div>

I’ve been battling this one for a while. I was originally using a bunch of Tweens to animate various sprites. My tweens were dying too soon and I read that if you simply stuck the tweens in a dictionary that garbage collection would no longer remove the tween before the tween was completed.

I ended up getting rid of the tweens altogether and resorted to using listeners on Event.ENTER\_FRAME, but I seem to be having the same problem. The problem is intermittent but sometimes my animations will stop too early and indeed my ENTER\_FRAME functions are stopping before I would like them to.

Perhaps what I am doing is too much (Animating size and color on 72 rectangle sprites while simultaneously drawing and rasterizing a pixelated ellipse animation), but maybe I am doing something wrong, I’m just getting back into Flash. Here is a snippet showing my ENTER\_FRAME listening:

```auto

public function animate(duration:Number) {
    var date:Date = new Date();
    animateStartTime = date.getTime();
    animateDuration = duration * 1000;
    this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

private function onEnterFrame(event:Event) {
    var date:Date = new Date();
    var currentTime:Number = date.getTime() - animateStartTime;
    var position = Strong.easeOut(currentTime, 0, 1, animateDuration);
    if (position >= 1) {
        this.graphics.clear();
        this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    render(position);
}

```
