# Alpha tween with AS

**URL:** <https://forum.kirupa.com/t/alpha-tween-with-as/31009>\
**Category:** flash\
**Created:** [September 17, 2003, 7:17am UTC](https://forum.kirupa.com/t/alpha-tween-with-as/31009 "2003-09-17T07:17:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lews](https://avatars.discourse-cdn.com/v4/letter/l/f0a364/32.png) [@Lews](https://forum.kirupa.com/u/Lews)\
**Post date:** [September 17, 2003, 7:17am UTC](https://forum.kirupa.com/t/alpha-tween-with-as/31009/1 "2003-09-17T07:17:36Z")

</div>

Hey,

I know this question has been asked a thousand times already, but I simply can’t get it to work.

I’ve looked at various other threads posts, but none of them seem to work.

Here’s what I’m trying to do:

I have a button (Instance name: “go”) and a MC (instance name: “fader”).

Now, I want the MC to fade in on rollOut and fade out on rollOut.

Currently, I have this code:

**In frame 1 of my movie: (taken from [this](http://www.kirupaforum.com/forums/showthread.php?threadid=30930&highlight=alpha) thread)**

[AS]  
Math.LT = function(t,b,c,d){  
return c\*t/d +b;  
};

MovieClip.prototype.fade = function(startVal, endVal, speed) {  
this.begin = startVal;  
this.finish = endVal;  
this.change = this.finish - this.begin;  
this.duration = speed;  
this.time = 0;  
this.onEnterFrame = function(){  
with (this) {  
\_alpha = math.LT(time++, begin, change, duration);  
if (time \> duration) delete this.onEnterFrame;  
}  
};  
};  
stop();

```auto

**In my button:**

```

on(rollOver)  
{  
fader.fade(0,100,5);  
}

on(rollOut)  
{  
fader.fade(100,0,5);  
}

```auto

But, like I said before, this does not work.
Note that just using "fader._alpha=<value>" in the rollOver/Out functions *does* work.

I've also tried it via the OnEnterFrame event, and that doesn't work either:

```

on(release)  
{  
fader.OnEnterFrame=function(){  
\_alpha-=5;  
if(\_alpha\<=0)  
delete OnEnterFrame;  
}  
}

```auto

Any ideas? :)
```
