This is the first tutorial I present on using the filters in Flash 8 with actionscript. In this tutorial we are creating a bouncing ball, which when moves is blurred depending on its speed. In addition we create a dropshadow, which becomes bigger when the ball is further away from the object it will hit, in this case a street. The tutorial is written as in AS2. But now let's start.

What do we need? We need a ball movieclip (mc), something which looks like a street or sidewalk, an invisible line (bottom) and a second ball (mc2) for the shadow. In the first part of the script we import the filter classes we need and create a number of variables.


		// importing the BlurFilter class
import flash.filters.BlurFilter;
		// creating the drop shadow
import flash.filters.DropShadowFilter;
		//
// defining all the variables
//
// ball
var mc:MovieClip;
		// ball behind to create shadow
var mc2:MovieClip;
		// the different heights of the ball
var yHeight1:Number;
yHeight1 = 0;
var yHeight2:Number;
yHeight2 = Stage.height;
		// the speed factor
var dy:Number;
		// intervall var
var speed:Number;
var movemc:Number;
		// the blur var
var blurX:Number;
var blurY:Number;
		
Next we create the shadow function. This is basically as described in the flash help files except that we change the angle and distance and keep it constant at one place. We also set hideObject to true, because we do not want the second ball to be revealed.

function makeShadow (mySpeed:Number) 
{
	// we modify the distance of the shadow depending on the distance of the ball
	// from the hit object.
	var distance:Number = 320-mc2._y;
	// we change the shadow angle according to height
	var angleInDegrees:Number = 80+2*mySpeed;
	var color:Number = 0x000000;
	var alpha:Number = .8;
	var dblurX:Number = 16;
	var dblurY:Number = 16;
	var strength:Number = 1;
	var dquality:Number = 3;
	var inner:Boolean = false;
	var knockout:Boolean = false;
	// we hide the second ball (mc2), since we only need the shadow
	var hideObject:Boolean = true;
	var dropfilter:DropShadowFilter = new DropShadowFilter (distance, angleInDegrees, color, alpha, 
dblurX, dblurY, strength, dquality, inner, knockout, hideObject);
	var dropfilterArray:Array = new Array ();
	dropfilterArray.push (dropfilter);
	// we attach the shadow to mc2, which is behind mc movieclip
	mc2.filters = dropfilterArray;
}
		
The next function is the blur function, the basics which you will find in the help files. We set a quality value of 3 and our blur object is mc.

		// calling the blur function
function blurObject (blurX, blurY) 
{
	// quality determines the extense of blur
	var quality:Number = 3;
	var filter:BlurFilter = new BlurFilter (blurX, blurY, quality);
	var filterArray:Array = new Array ();
	filterArray.push (filter);
	// we blur the outer ball
	mc.filters = filterArray;
}
		

Now we need to add movement into the scene and therefore we create intervals. In the first interval here we set the values for blurX and blurY depneding on the speed of the object as determined by dy. We also set the xscale factor for the shadow, which will change.


		// function
speed = setInterval (dxy2, 10);
function dxy2 () 
{
	// we increase the xscale of the ball shadow the further the ball is away 
	// from the bottom
	mc2._xscale = 500/(dy+1);
	if (mc2._xscale<100) 
	{
	       mc2._xscale = 100;
	}
	// here we create the shadow
	makeShadow (dy);
	// if the speed factor is below a certain value, there will be no blur
	if (dy<=1) 
	{
	       blurX = 0;
	       blurY = 0;
	       // ..else we create a blur depending on the speed for height
	} 
	else 
	{
	       blurX = 3;
	       blurY = 3*dy;
	}
	// executing the blur function
	blurObject (blurX, blurY);
}
		

Now we let the ball bounce and we define dy here. We need to add a Boolean (target) to make sure only one if statement is executed until the Boolean changes. We also change the dimensions of the ball when it hits the ground.


		// here we let the ball move
movemc = setInterval (bounce, 2);
function bounce () {
	// dy is the speedfactor, which increases when y of ball increases
	dy = (mc._y*10)/(yHeight2-yHeight1);
	// if the balls are above the bottom of the stage
	// and the boolean target is false...
	if (mc._y<Stage.height && !target) 
	{
	       // .. we let the balls fall down.
	       mc._y += dy;
	       mc2._y += dy;
	}
	// if the balls y is bigger 0 (the top of the stage)  
	// and the boolean target is true...
	if (mc._y>0 && target) 
	{
	       // ... we let the ball come up.
	       mc._y -= dy;
	       mc2._y -= dy;
	       // we make sure the balls have the right shape
	       mc._yscale = 100;
	       mc._xscale = 100;
	}
	// here we create the ball's obstacle, an invisible line, which  
	// when hit by the ball will cause a number of changes:
	// 1. boolean target is true; 
	// 2. we squeeze the ball by changing its shape to be realistic;
	// 3. we set the speedfactor to 0, which will stop the blur.
	if (mc.hitTest (bottom)) 
	{
	       target = true;
	       dy = 0;
	       mc._yscale = 75;
	       mc._xscale = 125;
	       mc2._yscale = 75;
	       mc2._xscale = 125;
	       // if the ball is at the top, we set the boolean target to false.
	} 
	else if (mc._y<=10) 
	{
	       target = false;
	}
}
		

This is the bases to create other movements of other objects with actionscript.