PDA

View Full Version : Alpha tween with AS



Lews
September 17th, 2003, 03:17 AM
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();
[/code]

In my button:


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

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


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


Any ideas? :)

Voetsjoeba
September 17th, 2003, 06:56 AM
Easy ...



fader._alpha=0;
go.onRollOver = function(){
fader.onEnterFrame = function(){
this._alpha>=100 ? delete this.onEnterFrame : this._alpha+=5
}
}
go.onRollOut = function(){
fader.onEnterFrame = function(){
this._alpha<=0 ? delete this.onEnterFrame : this._alpha-=5
}
}

And welcome to the forum =)

Lews
September 17th, 2003, 07:31 AM
Thanks :)

Voetsjoeba
September 17th, 2003, 07:38 AM
No problem :)