Do you remember this
first example "
Next is a second example of what can be obtained applying the BlurFilter to a MovieClip in runtime with Actionscript 3.0.
In this case, I will use sinus and co sinus applied to the BlurFilter...
I create a FLA and I save it as "main.fla".
Into which, I have a MovieClip placed on stage named "flep_mc".
I create the Document Class, an AS file saved as "Main.as", implemented the following way:
Code:
package
{
import flash.display.MovieClip;
import flash.filters.BlurFilter;
import flash.filters.BitmapFilterQuality;
import flash.events.Event;
public class Main extends MovieClip
{
private var angle:Number=-Math.PI/2;
private var speed:Number=.2;
private const RANGE:int=50;
public function Main()
{
init();
}
private function init():void
{
stage.frameRate=31;
flep_mc.addEventListener(Event.ENTER_FRAME,go);
}
private function go(evt:Event):void
{
var sine:Number=Math.sin(angle)*RANGE;
var cosine:Number=Math.cos(angle)*RANGE;
var blurX:int=cosine;
var blurY:int=sine;
var filter:BlurFilter=new BlurFilter(blurX,blurY,BitmapFilterQuality.HIGH);
var filters_array:Array=new Array();
filters_array.push(filter);
flep_mc.filters=filters_array;
angle+=speed;
}
}
}
the result:
Let us analyse the code
Properties
a numerical variable used as an angle value to which apply the sinus and co sinus
private var angle:Number=-Math.PI/2;
a numerical variable containing the speed to increase the angle
private var speed:Number=.2;
a constant used to multiply the sinus and co sinus (or the value would always be in between -1 and 1)
private const RANGE:int=50;
Constructor function
I call the method init
init();
Methods
init();
I impost the frame rate
stage.frameRate=31;
I add an ENTER_FRAME that will call the method go
flep_mc.addEventListener(Event.ENTER_FRAME,go);
go();
a local variable that calculates the sinus angle multiplied by the RANGE
var sine:Number=Math.sin(angle)*RANGE;
a local variable that calculates the co sinus angle multiplied by the RANGE
var cosine:Number=Math.cos(angle)*RANGE;
2 local variables into which I insert the values (sinus and co sinus) of the BlurFilter on the X and Y axes
var blurX:int=cosine;
var blurY:int=sine;
a local variable, instance of the BlurFilter
var filter:BlurFilter=new BlurFilter(blurX,blurY,BitmapFilterQuality.HIGH);
an Array into which insert the BlurFilter
var filters_array:Array=new Array();
I insert the BlurFilter into the Array using the method push
filters_array.push(filter);
I apply BlurFilter to the MovieClip placed on stage
flep_mc.filters=filters_array;
I increase the angle
angle+=speed;
If we wanted to have this effect play once, we should add the following code immediately after the angle has been increased.
Code:
if(angle>=Math.PI)
{
flep_mc.removeEventListener(Event.ENTER_FRAME,go);
flep_mc.filters=[];
trace('stop');
}
Stay tuned !