View Full Version : actionscript _alpha effect
jonsaul
01-13-2006, 01:15 PM
I was just wondering if anyone could explain how to add a fade up or in effect to _alpha (ie. when the _alpha code is run instead of going straight from "_alpha = 0;" to "_alpha = 100;" there is some kind of fade in/out effect, like with a tween)
I am using a very simple _alpha value in a button to show and hide Movieclips on the stage.(but at the moment it goes from invisible to visible with no in-between)
please let me know if you can help.
Thanx for any posts!!!
JonSaul
tobyw_1969
01-13-2006, 01:36 PM
You would need to use a repeating function, like an onEnterFrame, or a setInterval, so that you can adjust the _alpha value incrementally.
myClip_mc.fade = function(step:Number){
this.fadeStep = step;
this.onEnterFrame = function(){
this._alpha += this.step;
if(this._alpha>100 || this.alpha<0){
delete this.onEnterFrame;
delete this.fadeStep;
}
}
}
myClip_mc.fade(-5);
You could also define one function to control any clip you want to fade in and out, like this
function fadeClip(clip_mc:MovieClip, step:Number){
//create an empty mc to avoid conflicting with any existing onEnterFrame
var depth = clip_mc.getNextHighestDepth();
var fader_mc = clip_mc.createEmptyMovieClip("faderClip",depth);
fader_mc.step = step;
fader_mc.onEnterFrame = function(){
this._parent._alpha += step;
if(this._parent._alpha>100 || this._parent._alpha<0){
this.removeMovieClip();
}
}
}
fadeClip(myClip_mc,-5);
devilmaycry
01-13-2006, 01:44 PM
import mx.transitions.Tween;
function fadein(who:MovieClip,easeType:Function,Time:Number ){
who._alpha=0;
TweenID = new Tween(who, "_alpha", easeType, who._alpha, 100, Time, true);
}
use:
fadein(_root,mx.transitions.easing.Regular.easeOut ,1);
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.