mattkenefick
October 29th, 2008, 09:59 PM
I posted this identical thread on 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/
Code (uses two movieclips named item1_mc, item2_mc respectively):
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 );
-----------------------------
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/
Code (uses two movieclips named item1_mc, item2_mc respectively):
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 );