Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

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 to ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 20-11-07, 06:40
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
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 !
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !

Last edited by Flep; 28-08-08 at 06:29..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 25-06-08, 08:31
Junior Member
 
Join Date: Jun 2008
Posts: 1
Rep Power: 0
saxx is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
BlurFilter alle MovieClip con Actionscript 3.0 Flep Articoli e tutorials 63 26-04-08 18:17
BlurFilter at MovieClip with Actionscript 3.0 Flep Tutorials 1 04-04-08 03:01
BlurFilter alle MovieClip con Actionscript 3.0 - script 2 Flep Articoli e tutorials 23 29-11-07 13:09
Drawing with Actionscript 3.0 - script 2 Flep Tutorials 0 27-09-07 21:00
Disegnare con Actionscript 3.0 - script 3 Flep Articoli e tutorials 0 20-09-07 14:35


All times are GMT. The time now is 15:20.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap