Link to home
Start Free TrialLog in
Avatar of John Carney
John CarneyFlag for United States of America

asked on

In Flash MX2004, how do I turn this linear gradient box into a radial gradient circle?

How do I modify this action script so that it produces a circle with a concentric radial gradient, instead of a box with a linear gradient?

Thanks,
John
import flash.geom.*
//
var mc:MovieClip = this.createEmptyMovieClip("grad", 1);
 
var colors = [0x79986B, 0xDCE0B6, 0x79986B, 0x000000];
var alphas = [100, 100, 100,100];
var ratios = [0, 15, 30,45];
var matrix = {matrixType:"box", x:100, y:100, w:200, h:200, r:(45/180)*Math.PI};
mc.beginGradientFill("linear",colors,alphas,ratios,matrix);
mc.moveTo(100,100);
mc.lineTo(100,300);
mc.lineTo(300,300);
mc.lineTo(300,100);
mc.lineTo(100,100);
mc.endFill();

Open in new window

Avatar of Aneesh Chopra
Aneesh Chopra
Flag of India image

Just change "linear" to "radial"

you can also play with "ratios" array, to change the size of gradient circle.
for example, try replacing existing "radios" array with following:
var ratios = [0, 50, 100, 200];

here is the updated code:
import flash.geom.*;
//
var mc:MovieClip = this.createEmptyMovieClip("grad", 1);
 
var colors = [0x79986B, 0xDCE0B6, 0x79986B, 0x000000];
var alphas = [100, 100, 100, 100];
var ratios = [0, 15, 30, 45];
 
var matrix = {matrixType:"box", x:100, y:100, w:200, h:200, r:(45/180)*Math.PI};
mc.beginGradientFill("radial",colors,alphas,ratios,matrix);
mc.moveTo(100,100);
mc.lineTo(100,300);
mc.lineTo(300,300);
mc.lineTo(300,100);
mc.lineTo(100,100);
mc.endFill();

Open in new window

Avatar of John Carney

ASKER

Hi aneesh,

Yes that was the first thing i tried, but I still get a 200x200 black box around the much smaller circle gradient.bIs "box" an ActionScript defined term?  I thought maybe "circle" would get rid of the black box, but that produces no shape at all.

John
ASKER CERTIFIED SOLUTION
Avatar of Aneesh Chopra
Aneesh Chopra
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
another point,
"ratios" Array value should be set in incremental to each previous element of the array
and value should be inbetween 0 to 255

Thanks, aneesh. The main key was making that last alpha zero. Thanks for the continuing education.

Please take a look at this related quesion. If you have the time to post an answer now that would be awesome.

https://www.experts-exchange.com/questions/22990904/In-Flash-Mx2004-how-do-I-create-more-than-one-shape-with-Action-Script.html
welcome,
I just say the linked question and it has already been answered.

secondly,
if you are satisfy with my comment on this question.
Please close this question by accepting the appropriate comment