How can I animate an MC's alpha property with actionscript? I want to click a button and have an MC fade out without using a tween. Also, How can I add a delay in the script so that I could have a series of MCs fade out one after another when the button is clicked. Thanks
on the button which will fade out the mc. on (release) { this.onEnterFrame=function() { if (_root.mcname._alpha>0) { _root.mcname._alpha -= 1; // change the number according to how fast you want it to fade // } }; }
for a series of fades, loop through an array of your movieclip instance names, this example duplicates a movieclip instance - circ, adds its newname to the array and loops through, fading and removing clips until the array length is met, the onEnterFrame is then deleted to unburden the cpu. I hope this gives you some ideas, function dup(clip,amount,inc,val){ aClips = []; for(var j=0;j<=amount;j++){ duplicateMovieClip(clip,clip+j,j); rClip = this[clip+j]; rClip._x =(j*20)+15; rClip._alpha = 100; aClips[j] = rClip; aClips[j].onPress = function(){ fadeDown(0,inc,val); }; } }; function fadeDown(a,b,c){ this.onEnterFrame = function(){ aClips[a]._alpha >= 0 ? aClips[a]._alpha -= b : aClips[a].removeMovieClip(); aClips[a]._alpha <= c ? a++ : null; aClips[a-1]._alpha <= c ? aClips[a-1]._alpha -= b : null; a == aClips.length ? aClips[aClips.length-1]._alpha = 0 : null; a == aClips.length ? delete this.onEnterFrame : null; } }; targ = "circ"; dup(targ,25,20,20);
couldn't I use an interval to keep calling a function that looks to see if the first MC's alpha is 0, before changing the alpha of the second MC? I tried this code and it's not working. Am I doing something wrong? on (release) { this.onEnterFrame = function() { _root.MC1._alpha -= 5; myInterval = setInterval (fader, 10); function fader() { if(_root.MC1._alpha == 0) { _root.MC2._alpha -= 5; clearInterval(myInterval); }; }; }; }
Don't see what you're looking for? Try a search.
|