Alpha fade

using AS, on loading a movie a solid shape is there with alpha at 100% then over a period of 5 secs its alpha is reduced to 0.

i’m new to this…please help if you want to if you don’t have a good weekend but think of me struggling onwards and upwards…

keep the frame rate to 10fps. Draw the shape and convert it to a movie clip symbol with instance name “shape”. Now add a keyframe at frame 2 and one at frame 3. In the actions of frame one, add-
time=5
i=0
in frame 2 add-

i++
shape._alpha-=100 -time*i

in frame 3 add-

gotoAndPlay(2)

I hope that works!

*Originally posted by wilma *
**using AS, on loading a movie a solid shape is there with alpha at 100% then over a period of 5 secs its alpha is reduced to 0.

i’m new to this…please help if you want to if you don’t have a good weekend but think of me struggling onwards and upwards… **

If you are using Flash MX you can use dynamic event handlers to slowly fade the clip.

It would go a little something like this…

On a frame add these actions…

[AS]
clipInstanceName.onEnterFrame = function(){
this._alpha -= 5;
if (this._alpha <= 0){
this._alpha = 0;
delete this.onEnterFrame;
}[/AS]

very nice effect lostinbeta, works sweet,
i tried changing the effect to fade an image in, but no luck… is it simple?

to fade an image in, use- onClipEvent(load){_alpha=0}
and then use movieclip._alpha+=5

Hmm, I couldn’t get it to fade in…

this._alpha -= 5;

That line right there decreases the current alpha setting by 5. So if your clip alpha is 100, it will then be 95, then 90, then 85, etc, etc.

To increase the alpha just change -= to +=.

Now my question is this… are you trying to fade in and out successively? or are you just trying to fade a clip in and that is it?

Considering you just asked for fading in I won’t go the extra mile of in and out unless you need that.

[AS]
//start clips alpha setting at 0
clipInstanceName._alpha = 0;
//initiate clips onEnterFrame handler
clipInstanceName.onEnterFrame = function(){
//keep increasing the alpha by 5
this._alpha += 5;
//if the alpha setting is greater or equal to 100
if (this._alpha >= 100){
//keep it there
this._alpha = 100;
//and stop running the onEnterFrame
delete this.onEnterFrame;
}
}[/AS]

Thanks a heap ! =) i just added it to my menu with a fade on each.

Was just trying to load it in, tried the +, but forgot to add 100.

thanks again!

=)

yay! :thumb:

lostinbeta, thanks for your help on that. since you asked, yeh it would be good to get it to fade in and out successively… it would be great if you could show me that.

cheers for all your help.

Ok, to get it to work in and out like that you have to use a variable to hold a true or false value, we will call this variable “trigger”

[AS]
//start trigger at false
var trigger = false;
//start clips alpha setting at 0
clipInstanceName._alpha = 0;
//initiate clips onEnterFrame handler
clipInstanceName.onEnterFrame = function(){
//if trigger is false
if (!trigger){
//keep increasing the alpha by 5
this._alpha += 5;
//if the alpha setting is greater or equal to 100
if (this._alpha >= 100){
//set alpha to 100
this._alpha = 100;
//set trigger to true
trigger = true;
}
//else if trigger is true
} else {
//keep decreasing the alpha by 5
this._alpha -= 5;
//if the alpha setting is less than or equal to 0
if (this._alpha <= 0){
//set alpha to 0
this._alpha = 0;
//set trigger to false
trigger = false;
//trigger = false will make it fade back in
//to just stop it now change trigger=false to delete this.onEnterFrame
}

}
}[/AS]

var s = 5;
clipInstanceName._alpha = 0;
clipInstanceName.onEnterFrame = function() {
	s = this._alpha == 100 || this._alpha == 0 ? s*-1 : s;
	this._alpha = Math.min(Math.max(0, this._alpha+s), 100);
};

:wink: :stuck_out_tongue:

Kax, if you’ve got the time or the inclination to explain that code it would be most appreciated, if not no worries. but why, apart from the fact its a more consice piece of code, use yours as opposed to lostinbeta’s code??

thanks for all the help.

i really suck at explaining things, but here’s a brief explanation… hope that’s ok. :slight_smile:

s = this._alpha == 100 || this._alpha == 0 ? s*-1 : s;

if _alpha equals 100 or 0, change the value of s from a positive to negative or negative to positive value.

this._alpha = Math.min(Math.max(0, this._alpha+s), 100);

basically adds s to _alpha and keeps the value between 0 and 100.

and well, there’s no reason why you should use my code and not lostinbeta’s… make your choice and have fun! :stuck_out_tongue:

:thumb: good code, it is the fact that I can’t think like that that makes a lot of my coding inefficient.

I like th min/ max thing to keep it between 0 and 100. :thumb: