# Why can't I figure this out? SetInterval Problem

**URL:** <https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027>\
**Category:** Uncategorized\
**Created:** [August 19, 2004, 11:32pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027 "2004-08-19T23:32:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![trundrumbalind](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/trundrumbalind/32/696_2.png) [@trundrumbalind](https://forum.kirupa.com/u/trundrumbalind)\
**Post date:** [August 19, 2004, 11:32pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/1 "2004-08-19T23:32:24Z")

</div>

WHAT IS WRONG WITH ME!!??

OK, trying to fade out a button through a function. I’ve done this before but I’m tired and it’s just not happening.

OK, there’s a button named “button” and a movieclip named “fadeThis”. The first frame of the root has the following code in it:

```auto
fading = function(image) {
_root[image]._alpha -= 5;
}

```

And the button, “button”, has the following code in it:

```auto
on (release) {
fader = setInterval(_root.fading,10,fadeThis);
}

```

So WHY does the function fade the entire screen (“fadeThis” AND “button”)??

Thanks

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [August 20, 2004, 6:42am UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/2 "2004-08-20T06:42:22Z")

</div>

Don’t crosspost, one forum should be enough;)

scotty(-:

---

<div class="post-metadata">

**Author:** ![trundrumbalind](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/trundrumbalind/32/696_2.png) [@trundrumbalind](https://forum.kirupa.com/u/trundrumbalind)\
**Post date:** [August 20, 2004, 12:01pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/3 "2004-08-20T12:01:41Z")

</div>

Sorry. Won’t happen again.  
So does anyone actually have the answer to my problem or another way I should do it?

---

<div class="post-metadata">

**Author:** ![Voetsjoeba](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@Voetsjoeba](https://forum.kirupa.com/u/Voetsjoeba)\
**Post date:** [August 21, 2004, 3:33pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/4 "2004-08-21T15:33:55Z")

</div>

Try using an onEnterFrame handler to repeat the alpha diminish-[insert rest of word here].

```auto

{instance_name}.onRelease = function(){
auxmc = this._parent.createEmptyMovieClip("aux",999);
auxmc.onEnterFrame = function(){
this._parent.{instance_name}._alpha -= 2;
if(this._parent.{instance_name}._alpha <=0) delete this.onEnterFrame;
}
}

```

---

<div class="post-metadata">

**Author:** ![trundrumbalind](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/trundrumbalind/32/696_2.png) [@trundrumbalind](https://forum.kirupa.com/u/trundrumbalind)\
**Post date:** [August 21, 2004, 3:43pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/5 "2004-08-21T15:43:26Z")

</div>

Cheers, that’s great. But is it really necessary to get as complicated as that? It’s just that the whole thing works but it fades EVERYTHING out rather than just the graphic I want to fade out.

If I write it like this:

```auto
on (release) {
fader = setInterval(function {_root.fadeThis._alpha -= 5;},10);
}

```

It works perfectly. But I don’t want to do it like this, I want to use a functino that can have an image name passed to it. It just feels like I’m calling the image in the function wrong or something.

Thanks

---

<div class="post-metadata">

**Author:** ![Voetsjoeba](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@Voetsjoeba](https://forum.kirupa.com/u/Voetsjoeba)\
**Post date:** [August 21, 2004, 4:11pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/6 "2004-08-21T16:11:33Z")

</div>

IMO it’s better to use an onEnterFrame handler. With setInterval there’s the whole hassle with the scopes and the interval clearing and whatnot, an onEnterFrame handler is so much easier to use.

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [August 21, 2004, 4:44pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/7 "2004-08-21T16:44:02Z")

</div>

> [@trundrumbalind](#):
>
> Cheers, that’s great. But is it really necessary to get as complicated as that? It’s just that the whole thing works but it fades EVERYTHING out rather than just the graphic I want to fade out.
> 
> If I write it like this:
> 
> ```auto
> on (release) {
> fader = setInterval(function {_root.fadeThis._alpha -= 5;},10);
> }
> 
> ```
> 
> It works perfectly. But I don’t want to do it like this, I want to use a functino that can have an image name passed to it. It just feels like I’m calling the image in the function wrong or something.
> 
> Thanks

change your function to  
fading = function (image) {  
image.\_alpha -= 5;  
if (image.\_alpha\<0) {  
clearInterval(fader);  
}  
};

---

<div class="post-metadata">

**Author:** ![paradox244](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@paradox244](https://forum.kirupa.com/u/paradox244)\
**Post date:** [August 21, 2004, 5:46pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/8 "2004-08-21T17:46:28Z")

</div>

on (release) {  
fader = setInterval(\_root.fading,10,“fadeThis”);  
}

that might work a little better

---

<div class="post-metadata">

**Author:** ![trundrumbalind](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/trundrumbalind/32/696_2.png) [@trundrumbalind](https://forum.kirupa.com/u/trundrumbalind)\
**Post date:** [August 21, 2004, 10:47pm UTC](https://forum.kirupa.com/t/why-cant-i-figure-this-out-setinterval-problem/120027/9 "2004-08-21T22:47:28Z")

</div>

Good **MAN!!!**  
That’s it. Muchly appreciated.
