Why can't I figure this out? SetInterval Problem

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:

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

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

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

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

Thanks

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

scotty(-:

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

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


{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;
}
}

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:

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

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.

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

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

that might work a little better

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