我被一些我确信应该相当简单的事情所困扰。我从库中声明了两条垂直线,然后将每条线依次传递给一个函数,该函数在已传递的线上进行操作。代码执行没有错误,但显然在第二次调用函数时覆盖了第一行,大概是因为在函数头中使用了术语“myLine”。谁能告诉我如何将每一行传递给同一个函数,但该函数只在该行上运行?
代码是:
//declare new lines from library
var myLine1:letterLine = new letterLine();
var myLine2:letterLine = new letterLine();
//call function and pass each line in turn
VerticalLine(myLine1, lineX = stage.stageWidth/2 - lineOffset, lineY, lineLength, lineThickness, lineColour, lineTweenSpeed);
VerticalLine(myLine2, lineX = stage.stageWidth/2 - lineOffset, lineY, lineLength, lineThickness, lineColour, lineTweenSpeed);
//operate on the line passed to the function
function verticalLine(myLine, lineX:int, lineY:int, lineLength:Number, lineThickness:int, lineColour, lineTweenSpeed:Number):void {
//draw line
myLine.height = 0;
myLine.x = lineX;
myLine.y = lineY;
myLine.width = lineThickness;
var myColour:ColorTransform = myLine.transform.colorTransform;
myColour.color = lineColour;
myLine.transform.colorTransform = myColour;
addChild(myLine);
//set mask properties for line
var maskW:uint = lineThickness;
var maskH:uint = lineLength;
//set gradient properties for mask
var gradientFillType:String = GradientType.LINEAR;
var gradientColours:Array = [0x123456, 0x654321, 0x123456, 0x654321];
var gradientAlphas:Array = [0.4, 1, 1, 0.4];
var gradientRatios:Array = [0, 100, 155, 255];
var gradientMatrix:Matrix = new Matrix;
var maskRotation:Number = Math.PI/2;
var maskX:int = lineX;
var maskY:int = myLine.y - lineLength/2;;
gradientMatrix.createGradientBox(maskW, maskH, maskRotation, maskX, maskY);
var spreadMethod:String = SpreadMethod.PAD;
myLine.cacheAsBitmap = true;
//draw mask shape
var myMask = new Shape ;
myMask.graphics.beginGradientFill(gradientFillType, gradientColours, gradientAlphas, gradientRatios, gradientMatrix, spreadMethod);
myMask.graphics.drawRect(maskX, maskY, maskW, maskH);
myMask.cacheAsBitmap = true;
addChild(myMask);
//mask line
myLine.mask = myMask;
TweenLite.to(myLine, lineTweenSpeed,{height:lineLength, ease:Linear.easeIn});
}