Toxiclab.org

Gradient by Action Scipt

9.5.2006, 17:35
Submited in: Flash | Total Views: 40903

Learn how to create a gradient shape using the Action Script. For this tutorial I have used Flash Mx 2004.










Example 1

Open flash,open Action Script Pannel (F9) and paste this script:
createEmptyMovieClip ("gradient", 1);
with (gradient) {
colors = [0x323F2E, 0xD6E2D8 ];
alphas = [90,90];
ratios = [0,255];
matrix = {matrixType:"box", x:3, y:4, w:200, h:200, r:2}
beginGradientFill ("linear", colors, alphas, ratios, matrix);
moveTo(50,50);
lineTo(50,200);
lineTo(200,200);
lineTo(200,50);
lineTo(50,50);
endFill();
}

That script will generate this gradient shape:



Example 2
This script:
createEmptyMovieClip ("gradient", 1);
with (gradient) {
colors = [0x323F2E, 0xD6E2D8 ];
alphas = [90,100];
ratios = [0,255];
matrix = {a:40, b:0, c:15, d:0, e:100, f:15, g:100, h:215, i:12};
beginGradientFill ("linear", colors, alphas, ratios, matrix);
moveTo(15,15);
lineTo(15,150);
lineTo(150,150);
lineTo(150,15);
lineTo(15,15);
endFill();
}


will generate this gradient shape:



Explanation

method - beginGradientFill() fills in the shape with gradient and it has this syntax:

my_mc.beginGradientFill ( fillType, colors, alphas, ratios, matrix )

parameter fillType determines type of gradient which can be linear and radial,

parameter colors represents RGB (Red,Green,Blue),

parameter alphas represents the string of values which match with colours in string colors. ( values limited 0-100) ,

parameter ratios represents the string of coefficients of colour distribution ( values limited 0-255),

parameter matrix determines the method of gradient filling,

matrixType must be equal to "box", becouse the gradient will not be rightly filled,

x - represents the horizontal position of upper left side of gradient,

y - represents the vertical position of upper left side of gradient,

w - represents the width of gradient,

h - represents the height of gradient,

r - represents the rotation of gradient in radian.

Are you a website owner?
Click here to register and submit your tutorials!

Browse by category


Most popular tutorials


Resources Worth visiting


Friends