PDA

View Full Version : Fade with AS


Beaker
04-15-2003, 06:28 PM
I have a little button that when you roll over the alpha goes from 60 to 100, and when you mouse over I would like the alpha to go back to 60 BUT have it be a gentle fade. How can I do that?? This is the script I'm using so far and it works fine, minus the all important fade down to 60.

onClipEvent (load) {
this._alpha = 60;
}
on (rollOver) {
this._alpha = 100;
}
on (rollOut) {
this._alpha = 60;
}

CyanBlue
04-15-2003, 10:25 PM
Howdy...

Just made a sample in FMX for you...

Created a movieclip and gave it 'Btn' as an instance name...speed = 5;
Btn._alpha = 60;

Btn.onRollOver = function ()
{
this.onEnterFrame = function ()
{
if (this._alpha < 100)
{
this._alpha += speed;
}
else
{
delete this.onEnterFrame;
}
}
}

Btn.onRollOut = function ()
{
this.onEnterFrame = function ()
{
if (this._alpha > 60)
{
this._alpha -= speed;
}
else
{
delete this.onEnterFrame;
}
}
}

Beaker
04-15-2003, 11:16 PM
LOL!!! My jaw hit the floor when I saw all that code to do something so simple! Thanks for your work on this I really appreciate it, but I need the clip to go from 60 to 100 alpha instantly and then fade out like it does now.

Another question is why does the fade slow down when I change the 5 to a smaller number?

CyanBlue
04-15-2003, 11:28 PM
Um... Then your code will be looking like this...speed = 5;
Btn._alpha = 60;

Btn.onRollOver = function ()
{
this._alpha = 100;
}

Btn.onRollOut = function ()
{
this.onEnterFrame = function ()
{
if (this._alpha > 60)
{
this._alpha -= speed;
}
else
{
delete this.onEnterFrame;
}
}
}What the fade gets slower when you use smaller number??? Because it will be going something like this if speed is set to 1... 61, 62, 63, 64, 65, 66, 67, 68, whereas it will be 70, 80, 90, 100 if you set it to 10... Know what I mean??? ;)

Beaker
04-15-2003, 11:53 PM
CB, thanks so much this works perfectly!!!! :D :D

I know it must have been rather novice to you to change, but I am a total novice.:o Thanks again. :p :)

CyanBlue
04-16-2003, 01:07 PM
You're welcome... ;)

Nothing is easy... Just go on step by step and it won't take much time if you study hard... :)

Beaker
04-17-2003, 06:55 PM
One more question for you CB, could I have 2 different speeds for the fade in and fade out?

CyanBlue
04-18-2003, 02:48 AM
Well... You already have two speeds for rollOver and rollOut... Isn't it??? ;)

Please do some experimenting with the code that I have given you already... The only reason why I have provided the code is for you to learn what it needs to do things... If you are keep asking the same question over and over, it just means that you are not getting what I want you to understand... :(
And please don't call me CB cuz I am not... :(

Do some experiment and let me know if you need further assistance... ;)

Goose
04-19-2004, 01:39 PM
This is exactly what I've been looking for howver I'm very VERY new to AS. Is this possible to make work in Flash 5 player?
speed = 5;
Btn._alpha = 60;

Btn.onRollOver = function ()
{
this._alpha = 100;
}

Btn.onRollOut = function ()
{
this.onEnterFrame = function ()
{
if (this._alpha > 60)
{
this._alpha -= speed;
}
else
{
delete this.onEnterFrame;
}
}
}

teo
12-07-2006, 10:03 AM
well, I am quite new to AS (and absolutely to this forum! so hi all!), since I'm a designer....BUT
but always somenthing ragarding AS will occur during a project developement, so searched the forum and this seems the right thread.

I understood ( hope to!) the code here discussed, but I was wandering on how to modify it to obtain the the only fade-in of 4 ojects in sequence on the stage, with a timing of half a second one from the other.

this code seems that could modified conveniently, but i'm really a beginner so any help would be really appreciated.

thanks in advance, teo