# Actionscript Fading MovieClip Function

**URL:** <https://forum.kirupa.com/t/actionscript-fading-movieclip-function/189259>\
**Category:** open source\
**Created:** [June 1, 2006, 8:01am UTC](https://forum.kirupa.com/t/actionscript-fading-movieclip-function/189259 "2006-06-01T08:01:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![insaniak](https://avatars.discourse-cdn.com/v4/letter/i/ed8c4c/32.png) [@insaniak](https://forum.kirupa.com/u/insaniak)\
**Post date:** [June 1, 2006, 8:01am UTC](https://forum.kirupa.com/t/actionscript-fading-movieclip-function/189259/1 "2006-06-01T08:01:37Z")

</div>

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!

```
 [FONT=Courier New][LEFT][COLOR=#0000ff]import[/COLOR] flash.[COLOR=#000080]filters[/COLOR].[COLOR=#000080]BlurFilter[/COLOR];

```

max\_blur = i = [COLOR=#000080]30[/COLOR]; [COLOR=#808080]_//set the maximum blur value // i is variable to keep track of current blur value_[/COLOR]  
[COLOR=#0000ff]MovieClip[/COLOR].[COLOR=#0000ff]prototype[/COLOR].[COLOR=#000080]fade[/COLOR] = [COLOR=#000000] **function** [/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#808080]_//direc: 1=fadeOut, -1=fadeIn_[/COLOR]  
[COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]onEnterFrame[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]\_root[/COLOR].[COLOR=#000080]i[/COLOR]\<=\_root.[COLOR=#000080]max\_blur[/COLOR] && direc == -[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR] || [COLOR=#000000]([/COLOR][COLOR=#0000ff]\_root[/COLOR].[COLOR=#000080]i[/COLOR]\>=[COLOR=#000080]0[/COLOR] && direc == [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
myBlur = [COLOR=#000000] **new** [/COLOR] BlurFilterCOLOR=#000000[/COLOR];  
[COLOR=#0000ff]this[/COLOR].[COLOR=#000080]filters[/COLOR] = [COLOR=#000000][[/COLOR]myBlur[COLOR=#000000]][/COLOR];  
[COLOR=#0000ff]\_root[/COLOR].[COLOR=#000080]i[/COLOR] -= COLOR=#000000[/COLOR];  
[COLOR=#0000ff]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]\_root[/COLOR].[COLOR=#000080]i[/COLOR] \< [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#0000ff]\_root[/COLOR].[COLOR=#000080]i[/COLOR] = [COLOR=#000080]0[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]  
And you call it like this:

```
 [FONT=Courier New][LEFT]tape_mc.[COLOR=#000080]fade[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000080]7[/COLOR],[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];

```

[/LEFT]  
[/FONT]

\*\* Examples:\*\*  
**[HTML / SWF File | [URL=“http://www.pronto.plus.com/flash8/fade\_on\_rollover.fla”].fla file](http://www.pronto.plus.com/flash8/fade_on_rollover.html)**

Hope it’s useful :thumb:
