+ Reply to Thread
Results 1 to 2 of 2

Apply the BlurFilter to a MovieClip with Actionscript 3.0 - script 2

This is a discussion on Apply the BlurFilter to a MovieClip with Actionscript 3.0 - script 2 within the Tutorials forums, part of the Flash English category; Do you remember this first example " Next is a second example of what can be obtained applying the BlurFilter ...

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    Apply the BlurFilter to a MovieClip with Actionscript 3.0 - script 2

    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 !

  2. #2
    Junior Member Settled In saxx is on a distinguished road
    Join Date
    Jun 2008
    Posts
    1
    Rep Power
    0

    re: Apply the BlurFilter to a MovieClip with Actionscript 3.0 - script 2

    Could you please post the source thanks alot your forums have helped me a bunch

+ Reply to Thread

LinkBacks (?)


Similar Threads

  1. Script in AS3 per far scorrere movieClip
    By grazie1000 in forum Actionscript 3.0 avanzato
    Replies: 2
    Last Post: 17-06-09, 16:02
  2. Script in AS3 per far scorrere movieClip
    By grazie1000 in forum Actionscript 3.0 avanzato
    Replies: 0
    Last Post: 30-05-09, 13:28
  3. BlurFilter alle MovieClip con Actionscript 3.0
    By Flep in forum Articoli e tutorials
    Replies: 63
    Last Post: 26-04-08, 17:17
  4. Replies: 1
    Last Post: 04-04-08, 02:01
  5. BlurFilter alle MovieClip con Actionscript 3.0 - script 2
    By Flep in forum Articoli e tutorials
    Replies: 23
    Last Post: 29-11-07, 12:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts