圆角矩形和gradiant填写矩形、圆角、gradiant

2023-09-08 14:55:04 作者:南笙北执

试图让具有圆角和一个gradiant矩形。我有这个code

 进口flash.geom *。
VAR RECT:形状=新形状();
rect.graphics.lineStyle(5,0x00ff00,0); //(厚度,颜色,阿尔法)
VAR fillType:字符串=线性;
VAR颜色:数组= [0x000000处,0xFFFF00,0xFFFFFF]。
VAR阿尔法:阵列= [1,1,1];
VAR比率:数组= [0127255]
VAR矩阵:矩阵=新的Matrix();
matrix.createGradientBox(20,20,0,0,0);
rect.beginGradientFill(fillType,颜色,阿尔法,比,矩阵):无效;
rect.graphics.drawRoundRect(720450,213.4,29.1,12,12);
rect.graphics.endFill();
的addChild(RECT);
 

我得到一个错误,从该行:

  rect.beginGradientFill(fillType,颜色,阿尔法,比,矩阵):无效;
 

  

1078:标签必须是简单标识符。

林非常新手和每一件事我抬头,似乎有一堆术语我也不太明白,所以,请保持它的简单。

我要的黄色(FFFF00),以actualy从舞台上的色彩采摘,所以如果能在抛出他们的根本W / O混淆了上面的问题感到自由。

解决方案 如果只能选一种形状来做信息图,当然选矩形啊

在你的code你在同一行的两个错误:

  rect.beginGradientFill(fillType,颜色,阿尔法,比,矩阵):无效;
 

我们使用 无效 (低 v ,这不是 V OID)来表示函数的类型将返回当我们定义它,而不是调用该函数的时候什么都没有。

然后 beginGradientFill()图形类的功能,所以它应该是与使用 rect.graphics

  rect.graphics.beginGradientFill(fillType,颜色,阿尔法,比,矩阵);
 

那么你的code可以是这样的(这是一个例子):

  VAR fillType:字符串=线性;
VAR颜色:数组= [0x000000处,0xFFFF00,为0xFF0000]。
VAR阿尔法:数组= [1,1,1]。
变种比率:数组= [0,127,255]。
VAR矩阵:矩阵=新的Matrix();
    matrix.createGradientBox(200,10,0,0,0);

VAR RECT:形状=新形状();
    rect.graphics.lineStyle(5,0x00ff00,0);
    rect.graphics.beginGradientFill(fillType,颜色,阿尔法,比,矩阵)
    rect.graphics.drawRoundRect(0,0,200,200,12,12);
    rect.graphics.endFill();
的addChild(RECT);
 

有关更多的梯度,采取 Graphics.beginGradientFill() ,并在创建渐变线条和填充 ...

希望能有所帮助。

Trying to make a rectangle with rounded corners and a gradiant. I have this code

import flash.geom.*;
var rect:Shape = new Shape();
rect.graphics.lineStyle(5, 0x00ff00, 0); //(thickness, color, alpha)
var fillType:String = "linear";
var colors:Array = [0x000000, 0xFFFF00,0xFFFFFF];
var alphas:Array=[1,1,1];
var ratios:Array=[0,127,255];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(20, 20, 0, 0, 0);
rect.beginGradientFill(fillType, colors, alphas, ratios, matrix) : Void;
rect.graphics.drawRoundRect(720,450, 213.4, 29.1, 12, 12); 
rect.graphics.endFill();
addChild(rect);

I'm getting an error from this line :

rect.beginGradientFill(fillType, colors, alphas, ratios, matrix) : Void;

1078: Label must be simple identifier.

Im very novice and every thing I look up seems to have a bunch of terminology I don't quite understand, so please, keep it simple.

I want the yellow (FFFF00) to actualy be a color picked from the stage so if that can be thrown in their simply w/o confusing the above question feel free.

解决方案

In your code you have two errors in the same line :

rect.beginGradientFill(fillType, colors, alphas, ratios, matrix) : Void;

We use void ( with lower v, it's not Void ) to indicate the type of a function which will return nothing when we are defining it, not when calling that function.

Then beginGradientFill() is a function of the Graphics class so it should be used with rect.graphics :

rect.graphics.beginGradientFill(fillType, colors, alphas, ratios, matrix);

Then your code can be like this (it's an example) :

var fillType:String = "linear";
var colors:Array = [0x000000, 0xFFFF00, 0xFF0000];
var alphas:Array=[1, 1, 1];
var ratios:Array=[0, 127, 255];
var matrix:Matrix = new Matrix();
    matrix.createGradientBox(200, 10, 0, 0, 0);

var rect:Shape = new Shape();
    rect.graphics.lineStyle(5, 0x00ff00, 0); 
    rect.graphics.beginGradientFill(fillType, colors, alphas, ratios, matrix)
    rect.graphics.drawRoundRect(0, 0, 200, 200, 12, 12); 
    rect.graphics.endFill();
addChild(rect);

For more about gradient, take a look on Graphics.beginGradientFill(), and on creating gradient lines and fills ...

Hope that can help.