# Free Code: Classy Auto-Drop Shadows

**URL:** <https://forum.kirupa.com/t/free-code-classy-auto-drop-shadows/274444>\
**Category:** flash\
**Created:** [October 30, 2008, 1:59am UTC](https://forum.kirupa.com/t/free-code-classy-auto-drop-shadows/274444 "2008-10-30T01:59:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattkenefick](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mattkenefick](https://forum.kirupa.com/u/mattkenefick)\
**Post date:** [October 30, 2008, 1:59am UTC](https://forum.kirupa.com/t/free-code-classy-auto-drop-shadows/274444/1 "2008-10-30T01:59:59Z")

</div>

I posted this identical thread on [Actionscript.org](http://Actionscript.org) as well. I thought maybe someone here might find it useful at some point too perhaps. Free code never hurts.

* * *

This creates those kinds of thin drop shadows that stay at the base of an object and give a subtle bit of depth and realism.

See example and code here: [http://mattkenefick.com/blog/2008/10/classy-drop-shadows-for-objects/](http://mattkenefick.com/blog/2008/10/classy-drop-shadows-for-objects/)

Code (uses two movieclips named item1\_mc, item2\_mc respectively):

```auto
function createShadow( item:MovieClip, offset = 10, fade:Number = 1, shadowHeight:int = 20 ){
    var itemShadow:Sprite = new Sprite();
    var gfx:Graphics = itemShadow.graphics;
    var matrix:Matrix = new Matrix();
    var realDimensions = item.getBounds(item.parent);
    
    matrix.createGradientBox( item.width, item.height );
    gfx.beginGradientFill("radial", [0x000000, 0x000000], [fade,0],[0,255],matrix);
    gfx.drawRect(0,0,item.width,item.height);
    gfx.endFill();
    
    itemShadow.y = realDimensions.y + item.height + offset;
    itemShadow.x = realDimensions.x;
    itemShadow.height = shadowHeight;
    itemShadow.blendMode = "multiply"
    
    addChild( itemShadow );
}

createShadow( item1_mc, 50, .5, 10 );
createShadow( item2_mc, 20, .7, 15 );

```
