#1 (permalink)  
Old 27-09-07, 08:41
Administrator
Living At The FlepStudio!
 
Join Date: Jul 2007
Location: Cesenatico
Posts: 4,917
Rep Power: 6
Flep is on a distinguished road
Drawing with Actionscript 3.0 - script 3

Greetings :P

Third appointment with the runtime drawing.
Third appointment with the Drawing API of Actionscript 3.0.
In this article, I will use the beginGradientFill mehod together with a Matrix similar to GradientBox.
As always, I invite you, once the script studied, to try yourself some experiments giving space to your fantasy...and...why not, if you fancy it, to publish them on the forum of this site, you are more then welcome and I would be pleased you do so :)

Let's get into the script...

I create a FLA and save it as 'disegno3.fla'.
I create a Document Class, an AS file saved as 'Disegno3.as', implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	import flash.display.GradientType;
	import flash.display.InterpolationMethod;
	import flash.display.SpreadMethod;
	import flash.geom.Matrix;
	import flash.events.Event;
	
	public class Disegno3 extends MovieClip
	{
		private var clip:MovieClip;

		private var colors_array:Array;
		private var rapporti_array:Array;
		
		private var sine:Number;
		private var angle:Number=0;

		public function Disegno3()
		{
			init();
		}
		
		private function init():void
		{
			stage.frameRate=31;
			
			colors_array=new Array('0xB16363','0x763A3A','0xECE9D8');
			rapporti_array=new Array(0,200,255);
			
			clip=new MovieClip();
			this.addChild(clip);
			
			this.addEventListener(Event.ENTER_FRAME,disegna);
		}
		
		private function disegna(e:Event):void
		{
			this.removeChild(clip);
			
			sine=Math.sin(angle)*20;
			
			var alphas:Array=new Array(sine,1,1);
			var matrix:Matrix=new Matrix();
			matrix.createGradientBox(200,100,sine,stage.stageWidth/4,stage.stageHeight/2);
			
			clip=new MovieClip();
			clip.graphics.clear();
			clip.graphics.beginGradientFill(GradientType.RADIAL,colors_array,alphas,
			rapporti_array,matrix,SpreadMethod.REFLECT,
			InterpolationMethod.RGB,.7);
			clip.graphics.lineTo(stage.stageWidth,0);
			clip.graphics.lineTo(stage.stageWidth,stage.stageHeight);
			clip.graphics.lineTo(0,stage.stageHeight);
			clip.graphics.endFill();
			
			angle+=.01;
			
			this.addChild(clip);
		}
	}
}
The result:







Let's analise the code.

Properties

a MovieClip into which I will design
private var clip:MovieClip;
an array containing the colors I wish to use
private var colors_array:Array;
an array containing the color distribution ratios.
private var rapporti_array:Array;
a numerical number containing the sinus
private var sine:Number;
a numerical value containing the value of the angle from which the sinus will be calculated and which will be increased
private var angle:Number=0;



Methods
init();
I impost the frame rate
stage.frameRate=31;
I initialize the colors array
colors_array=new Array('0xB16363','0x763A3A','0xECE9D8');
I initialize the ratios array
rapporti_array=new Array(0,200,255);
I create a new MovieClip and add it to the stage (otherwise it would not be visibile)
clip=new MovieClip();
this.addChild(clip);
I add a listener to the ENTER_FRAME which will call the method disegna() as many time by seconds based on the frame rate
this.addEventListener(Event.ENTER_FRAME,disegna);

disegna();
I remove the clip
NB: the fact of creating and then removing the clip, is necessary. At each interval, I remove the clip to free some memory and if I would not do so here in the function init, Flash would now give me an error as the clip would be equal to null.
this.removeChild(clip);
I calculate the angle's sinus (variable 'angle')
sine=Math.sin(angle)*20;
I create an array containing the alpha of each color used
var alphas:Array=new Array(sine,1,1);
I create a Matrix
var matrix:Matrix=new Matrix();
I define the type as GradientBox using the Matrix.createGradientBox class using 5 parameters: width, height, rotation, x and y.
matrix.createGradientBox(200,100,sine,stage.stageW idth/4,stage.stageHeight/2);
I create a new Movie Clip
clip=new MovieClip();
I clean up the MovieClip graphics
clip.graphics.clear();
I use the beginGradientFill using the following parameters:
- type of gradient (radial, linear?) passed using the static method RADIAL of the GradientType class
- an array containing the alpha values, so I pass the array_alphas
- an array containing the color distribution ratios, so I pass rapporti_array
- a matrix which would be ?matrix? of Box type
- a value to define the extension of the gradient. I use the static method REFLECT of the SpreadMethod class
- a value to define the interpolation of the gradient?s color. I use the static method RGB of the InterpolationMethod class
- a numerical value which points to the gradient's center
clip.graphics.beginGradientFill(GradientType.RADIA L,colors_array,alphas,rapporti_array,matrix,Spread Method.REFLECT,InterpolationMethod.RGB,.7);
I design with the clip
clip.graphics.lineTo(stage.stageWidth,0);
clip.graphics.lineTo(stage.stageWidth,stage.stageH eight);
clip.graphics.lineTo(0,stage.stageHeight);
clip.graphics.endFill();
I increase the angle
angle+=.01;
I add the clip to the DisplayObject
this.addChild(clip);

Have fun !
__________________
_________________________________________
VIDEO CORSI ACTIONSCRIPT 3.0 creati da FlepStudio
I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread please !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
sponsor links
Flashmint flash templates FlippingBook-PDF publisher Flash Media Server Hosting
sponsor links
Reply

Bookmarks

Tags
actionscript, drawing, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Drawing polygons with Actionscript 3.0 Flep Tutorials 1 27-09-08 23:10
Disegnare con Actionscript 3.0 - script 1 Flep Articoli e tutorials 3 26-08-08 19:02
Drawing with actionscript 3.0 Flep Tutorials 0 03-10-07 18:34
Drawing with Actionscript 3.0 - script 2 Flep Tutorials 0 27-09-07 20:00
Disegnare con Actionscript 3.0 - script 2 Flep Articoli e tutorials 0 20-09-07 11:43



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
vBulletin Skin developed by: vBStyles.com
FlepStudio 2007-2009