# 'delete this.onEnterFrame' troubles

**URL:** <https://forum.kirupa.com/t/delete-this-onenterframe-troubles/186414>\
**Category:** flash\
**Created:** [April 21, 2006, 2:40am UTC](https://forum.kirupa.com/t/delete-this-onenterframe-troubles/186414 "2006-04-21T02:40:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![East\_High](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@East\_High](https://forum.kirupa.com/u/East_High)\
**Post date:** [April 21, 2006, 2:40am UTC](https://forum.kirupa.com/t/delete-this-onenterframe-troubles/186414/1 "2006-04-21T02:40:17Z")

</div>

I’m using a number of onEnterFrame functions in my project and to slow down the CPU consumption I want to delete them when they’ve done their job. I’ve got this code to work with things like alpha fades, but the delete this.onEnterFrame doesn’t work with the easeing code. I think it’s the division part of the code that’s affecting it. Can someone lend me a hand?  
Thanks,  
GD

```auto
var targetY = 220;
this.onEnterFrame = function() {
	if (blank_mc._y<targetY) {
		blank_mc._y += (targetY-blank_mc._y)/10;
		trace("ease");
		if (blank_mc._y>targetY) {
			delete this.onEnterFrame;
		}
	}
};

```

---

<div class="post-metadata">

**Author:** ![Balala](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@Balala](https://forum.kirupa.com/u/Balala)\
**Post date:** [April 21, 2006, 2:49am UTC](https://forum.kirupa.com/t/delete-this-onenterframe-troubles/186414/2 "2006-04-21T02:49:45Z")

</div>

Lets make some output here:

blank\_mc.\_y += (targetY-blank\_mc.\_y)/10;

```auto
(220 - 0) / 10 = 22
(220 - 22) / 10 = 19.8
...
...
(220 - 219) / 10 = 0.1
(220 - 219.1) / 10 = 0.09
(220 - 219.19) / 10 = 0.81

```

See? Never gona be higher then the targetY. If you want 10 steps to get to final destination, so, keep the first value in a variable.

---

<div class="post-metadata">

**Author:** ![East\_High](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@East\_High](https://forum.kirupa.com/u/East_High)\
**Post date:** [April 21, 2006, 3:45am UTC](https://forum.kirupa.com/t/delete-this-onenterframe-troubles/186414/3 "2006-04-21T03:45:10Z")

</div>

> [@Balala](#):
>
> Lets make some output here:
> 
> blank\_mc.\_y += (targetY-blank\_mc.\_y)/10;
> 
> ```auto
> (220 - 0) / 10 = 22
> (220 - 22) / 10 = 19.8
> ...
> ...
> (220 - 219) / 10 = 0.1
> (220 - 219.1) / 10 = 0.09
> (220 - 219.19) / 10 = 0.81
> 
> ```
> 
> See? Never gona be higher then the targetY. If you want 10 steps to get to final destination, so, keep the first value in a variable.

:h: I’m afraid I’m not following… can you explain further?

---

<div class="post-metadata">

**Author:** ![Macaroni\_Ted](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Macaroni\_Ted](https://forum.kirupa.com/u/Macaroni_Ted)\
**Post date:** [April 21, 2006, 4:39am UTC](https://forum.kirupa.com/t/delete-this-onenterframe-troubles/186414/4 "2006-04-21T04:39:42Z")

</div>

> [@East High](#):
>
> :h: I’m afraid I’m not following… can you explain further?

Balala ment that the blank\_mc.\_y will never reach the targetY so it keeps looping.

try  
[AS]  
var targetY = 220;  
this.onEnterFrame = function() {  
if (Math.abs(blank\_mc.\_y-targetY)\>1) {  
blank\_mc.\_y += (targetY-blank\_mc.\_y)/10;  
trace(“ease”);  
}else {  
delete this.onEnterFrame;  
}  
};  
[/AS]

---

<div class="post-metadata">

**Author:** ![East\_High](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@East\_High](https://forum.kirupa.com/u/East_High)\
**Post date:** [April 21, 2006, 5:19am UTC](https://forum.kirupa.com/t/delete-this-onenterframe-troubles/186414/5 "2006-04-21T05:19:13Z")

</div>

I think I got it. thanks guys:)
