PDA

View Full Version : Manipulating Gradient Fills via AS3



Wedge_Man
June 24th, 2007, 06:29 PM
Hey Guys,

So i have the following code...


function Light(_type:String, _xCo:Number, _yCo:Number, _w:Number, _colors:Array, _alphas:Array, _ratios:Array, _stageRef:Stage) {
stage = _stageRef;


movieClip = new MovieClip();
movieClip.graphics.beginGradientFill(GradientType. RADIAL, _colors, _alphas, _ratios);
movieClip.graphics.drawEllipse((-_w/2), (-_w/4), _w, _w/2);
movieClip.graphics.endFill();
movieClip.blendMode = BlendMode.SCREEN;
movieClip.alpha = 0.6;
movieClip.cacheAsBitmap = true;
movieClip.mouseEnabled = false;
xNum = ((_xCo + 1) * 50);
yNum = ((_yCo + 1) * 25);
}

Which draws a very nice oval on the screen like i want it to, however the gradient is still drawn as if it were a circle.

If i go into the Flash IDE, I can select the graident tool and then "squash" the graident so it fits the oval.

My question is how can I use actionscript to have the gradient be 1/2 as high as it is wide?

Thanks!

TheCanadian
June 24th, 2007, 06:37 PM
You have to use the matrix parameter of the beginGradientFill method.

Wedge_Man
June 24th, 2007, 07:13 PM
Sorry, is there an example of implementing that?