PDA

View Full Version : Actionscript Fading MovieClip Function



insaniak
June 1st, 2006, 04:01 AM
I'm getting quite into this Flash 8 way of working now :).

You call the code on the movieclip like: mc_name.fade(speed,direction) - where speed is a number between 0 and your max_blur value, and direction is 1 to fade away, and -1 to fade up. max_blur is the maximum amount you want the image to blur by!


import flash.filters.BlurFilter;

max_blur = i = 30; //set the maximum blur value // i is variable to keep track of current blur value
MovieClip.prototype.fade = function (speed,direc) { //direc: 1=fadeOut, -1=fadeIn
this.onEnterFrame = function(){
if((_root.i<=_root.max_blur && direc == -1) || (_root.i>=0 && direc == 1)){
myBlur = new BlurFilter(_root.i,_root.i,1);
this.filters = [myBlur];
_root.i -= (speed*direc);
if(_root.i < 0) _root.i = 0;
}
}
}


And you call it like this:


tape_mc.fade(7,1);



Examples:
HTML / SWF File (http://www.pronto.plus.com/flash8/fade_on_rollover.html) | .fla file (http://www.pronto.plus.com/flash8/fade_on_rollover.fla)

Hope it's useful :thumb:

theflash
June 1st, 2006, 04:13 AM
Simple but useful :)

insaniak
June 1st, 2006, 04:40 AM
Cheers :) - Someone might find it useful

serkios
June 2nd, 2006, 04:35 PM
Cool!

(ow my eyes!)

glosrfc
June 2nd, 2006, 04:56 PM
Strange...it works fine the first time I rollover, but on each subsequent rollover there's a little judder at the start of the blur.

insaniak
June 2nd, 2006, 05:12 PM
Well spotted!! Hadn't noticed that before - should be fixed now. I had it testing < rather than <= to the max_blur value.

Thanks for the comments. Have edited original post and uploaded new file (you will need to clear the old version from your cache to see the change) :)

glosrfc
June 2nd, 2006, 05:35 PM
Works fine now :)

Not sure why, but the fla link insists on downloading as a Word document too. Good stuff though, I can think of a few uses for this already.

insaniak
June 2nd, 2006, 06:00 PM
Yes - something must be corrupted with my uploading of the .fla files. Ever .fla iv uploaded to Kirupa turns up as a Word Document. Just save it and rename it and it works fine :).

Send me an email if you need a copy and ill email it your way.

glosrfc
June 2nd, 2006, 06:38 PM
No problem, I just renamed it. Must be a mime thing - I'm sure your hosting company can sort it out.