# Help shut off a tween pls- eating CPU

**URL:** <https://forum.kirupa.com/t/help-shut-off-a-tween-pls-eating-cpu/203025>\
**Category:** flash\
**Created:** [October 6, 2006, 5:39pm UTC](https://forum.kirupa.com/t/help-shut-off-a-tween-pls-eating-cpu/203025 "2006-10-06T17:39:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmart](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@cmart](https://forum.kirupa.com/u/cmart)\
**Post date:** [October 6, 2006, 5:39pm UTC](https://forum.kirupa.com/t/help-shut-off-a-tween-pls-eating-cpu/203025/1 "2006-10-06T17:39:23Z")

</div>

Hello. This was originally a move tween that I modified to be an elastic scale tween:

```auto

MovieClip.prototype.scaleItElastic = function (scalex, scaley, inertia, k) { 
    vx = -this._xscale+scalex;
    vy = -this._yscale+scaley;
    this.xp = this.xp*inertia+vx*k;
    this.yp = this.yp*inertia+vy*k;
    this._xscale += this.xp;
    this._yscale += this.yp;
}

```

on the to-be-tweened movieclip when it loads:

```auto

onClipEvent(load) {
// set MC scale to 0
    this._xscale = 0;
    this._yscale = 0;
//
    var xp = 0;
    var yp = 0;

}

```

and finally the function to call it on a keyframe:

```auto

onEnterFrame = function () {
	trace("running");

	if (this.copy_mc._xscale == 100) {
		this.copyStatus = "loaded";
		trace("elastic function shut off");
		delete this.onEnterFrame;
//else
}
	else if (this.copyStatus != "loaded") {
		this.copy_mc.scaleItElastic(100, 100, .75, 0.1);
}
}

```

Works great EXCEPT, the function is very CPU intensive because even though the tween is no longer VISIBLY working (the clip has no more elasticity), it continues to run in the background for 5-8 seconds after the last visible movement has occured.

i tried to take care of this with this part of the above actionscript (see below), but it seems that the scale is passing back and forth through 100% that the code is failing to work until the passing has truly stopped. Any way to get this code to stop after 1 or two springs? Or after 2 seconds or so?

```auto

if (this.copy_mc._xscale == 100) {
		this.copyStatus = "loaded";
		trace("elastic function shut off");
		delete this.onEnterFrame;

```
