Let's say I have a complex shaped MovieClip with a gradient color (A -> B) on the stage and I want to change the begin and end colors of the gradient at run-time.

Is it possible?

有帮助吗?

解决方案

If you drew this MovieClip with your mouse it is not possible. If you want to do so, you could have your gradient in a rectangle MovieClip with a mask over it. The mask will have the shape of your current gradient. Then in AS3 you could redraw the gradient in the MovieClip (called gradientZone in the example below).

var matr:Matrix = new Matrix();
matr.createGradientBox(gradientZone.width, gradientZone.height, 0, 0, 0);
gradientZone.graphics.clear();
gradientZone.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x0000FF], [1, 1], [0x00, 0xFF], matr);        
gradientZone.graphics.drawRect(0,0,gradientZone.width, gradientZone.height);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top